Wsl Issue with Importing Packages and Opening Files Within Python Scripts

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
Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.