0

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!

trinity
  • 23
  • I don't think you will be able to access Windows C: in that way - see for example Can I change directory to a Windows drive in Ubuntu Bash on WSL? – steeldriver Apr 20 '21 at 18:10
  • @steeldriver Thanks for your input. Tried running it through my mnt alias that goes /mnt/c/Users/18687 then cd-ing to the folder but still can't run the scripts that open files or import packages. Is that what you meant for me to try? – trinity Apr 20 '21 at 18:19
  • Correct, Ubuntu does not recognize the windows way of access a drive (C:). You need to find where Ubuntu mounts your C: drive and use that in the path. – Eagle_Mike Apr 20 '21 at 18:20
  • Nice!! using with open(r"/mnt/c/Users/18687/Desktop/Bio Informatics/Bioinformatics specialization/testsets/farthestfirsttraversal.txt", "r") as file: did the trick for running scripts in ubuntu!

    Could you comment on the issue of running scripts that import packages? Thank you!

    – trinity Apr 20 '21 at 18:37

0 Answers0