WSL issue with importing packages and opening files within python scripts

I've recently started using the WSL with Ubuntu version:

Description: Ubuntu 20.04.2 LTS

Release: 20.04

Prior to this I have installed all packages through the Windows Powershell Terminal using pip install. Haven't installed pip3 on Ubuntu nor any packages through the terminal.

I'm able to navigate through my file system properly and can run simple scripts that just use variables and maybe a function using

python3 myscript.py

But cannot run scripts that read a file, receiving error:

$>> python3 farthest_first_traversal.py
Traceback (most recent call last): File "farthest_first_traversal.py", line 60, in <module> with open(r"C:\Users\18687\Desktop\Bio Informatics\Bioinformatics specialization\testsets\farthestfirsttraversal.txt", "r") as file:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\18687\\Desktop\\Bio Informatics\\Bioinformatics specialization\\testsets\\farthestfirsttraversal.txt'

I'm positive this is the correct path.

Secondly, I am not able to run scripts that import a package, receiving error:

$>> python3 lloyd_algorithm.py
Traceback (most recent call last): File "lloyd_algorithm.py", line 9, in <module> import numpy as np
ModuleNotFoundError: No module named 'numpy'

Each of these scripts run as expected within my IDE (vsc).

TRIED:

1) adding

PYTHONPATH=$C:\Users\18687\AppData\Local\Programs\Python\Python39\Lib\site-packages
export PYTHONPATH 

to the .bash_profile AND to the .bashrc files.

2)

Make sure the first line of your file has #!/usr/bin/env python3.

Make it executable - chmod +x filename.py.

And run it as ./filename.py

Since I'm new to Ubuntu and using the terminal in general I've messed up several times already trying to tinker things myself unfortunately. High time I start asking for help :( Thank you for your time!

4 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like