Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't import python module from separate partition

I recently copied my "scripts" folder to a seperate partition (from C:\ to drive D:\ ) while the python interpreter (v2.7.13) is still on C:\ . Subsequently I updated my $PATH to include the new path.

Now I try to execute a python script that imports modules from my "scripts" and it cannot find those modules:

Traceback (most recent call last):
   File "neue_aufgabe.py", line 15, in <module>
      from CustomUtils.UI.PyQtUI import *
ImportError: No module named CustomUtils.UI.PyQtUI

So, we have:


Interpreter on C:\

Modules on D:\

Script to be run on D:\


I deleted all the stale pyc files from all module directories. Is it just that the interpreter cannot import a module from a seperate partition?

like image 875
Niko Avatar asked Apr 06 '26 03:04

Niko


1 Answers

You need to append your new folder to PYTHONPATH environment variable rather than PATH.

Alternatively you can set it in the script itself by putting this at the top (though not usually recommended in production)

import sys
sys.path.append('/path/to/your/modules')
like image 164
Cfreak Avatar answered Apr 08 '26 19:04

Cfreak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!