Windows 10 Bash and python paths

ⅰ亾dé卋堺 提交于 2020-02-02 11:11:06

问题


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?


回答1:


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])



回答2:


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"


来源:https://stackoverflow.com/questions/41617029/windows-10-bash-and-python-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!