Mario Viti
Mario Viti

Reputation: 634

Windows 10 Bash and python paths

I've recently installed the windows bash. I tryed to make the packages installed with Anaconda visible by adding them to the PYTHONPATH variable but it is not listed in the environment.

Couriously enough sys.path.append works just fine and has entries, as sys.path doc states that the package variable is instatiated from the environment variable PYTHONPATH, but how can it be if it is not present in the environment (Bash of windows)?

I've already checked the windows environment and they're as separated system (otherwise the Anaconda packages would be available for import). So where can I set the python paths to new modules in windows bash?

Upvotes: 2

Views: 4220

Answers (2)

joshua
joshua

Reputation: 2519

If you are launching python from windows bash it won't automatically find your PYTHONPATH environment variable from windows. You need to add it yourself. You can do this by editing the .bashrc file. It is located in your home directory (/home/userid or just ~).

vi ~/.bashrc

Now add the following line:

export PYTHONPATH="/mnt/c/my/python/path"

Upvotes: 1

Nikolay Prokopyev
Nikolay Prokopyev

Reputation: 1312

If you are using some IDE like PyCharm, it may create it's own PYTHONPATH. It certainly won't be visible from system.

You may create PYTHONPATH variable on your own from system settings (Control Panel etc). But if something like IDE then replace it locally, your modules won't be able to import.

The stable but a bit rude way is modify the windows registry by modifying a value in PYTHONPATH record.

The code that uses RapidEE utility (RAPIDEE_EXECUTABLE is path to your rapidee.exe) to achieve that

def set_pythonpath():
    subprocess.call([RAPIDEE_EXECUTABLE, '-S', '-C', 'PYTHONPATH', YOUR_PACKAGE_PATH])

Upvotes: 0

Related Questions