Questions tagged [pythonpath]

PYTHONPATH is an environment variable that can be used to augment the default search path for module imports in Python.

PYTHONPATH is an environment variable that can be used to augment the default search path for module files in Python. Values will be added to sys.path.

758 questions
497
votes
10 answers

How do I find out my PYTHONPATH using Python?

How do I find out which directories are listed in my system’s PYTHONPATH variable, from within a Python script (or the interactive shell)?
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
466
votes
23 answers

How to add to the PYTHONPATH in Windows, so it finds my modules/packages?

I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly. I tried adding C:\My_Projects\; to my Windows Path variable from the Windows GUI (My Computer >…
darren
  • 18,845
  • 17
  • 60
  • 79
450
votes
24 answers

Permanently add a directory to PYTHONPATH?

Whenever I use sys.path.append, the new directory will be added. However, once I close python, the list will revert to the previous (default?) values. How do I permanently add a directory to PYTHONPATH?
John Howard
  • 61,037
  • 23
  • 50
  • 66
319
votes
34 answers

PyLint "Unable to import" error - how to set PYTHONPATH?

I'm running PyLint from inside Wing IDE on Windows. I have a sub-directory (package) in my project and inside the package I import a module from the top level, ie. __init__.py myapp.py one.py subdir\ __init__.py two.py Inside two.py I have…
EMP
  • 59,148
  • 53
  • 164
  • 220
205
votes
32 answers

django import error - No module named core.management

Ok, I see plenty of these errors around. I have tried everything I know to do and have yet to figure this out. I am working on a development server running python 2.5 and Django 1.3. Django 1.3 was installed using python setup.py install after…
grantk
  • 3,958
  • 4
  • 28
  • 37
178
votes
5 answers

adding directory to sys.path /PYTHONPATH

I am trying to import a module from a particular directory. The problem is that if I use sys.path.append(mod_directory) to append the path and then open the python interpreter, the directory mod_directory gets added to the end of the list sys.path.…
UnadulteratedImagination
  • 1,971
  • 2
  • 13
  • 15
124
votes
13 answers

How to correctly set PYTHONPATH for Visual Studio Code

How do I correctly set up the $PYTHONPATH variable for my workspace in VisualStudio Code? Background Information I have installed two versions of GNURadio: GNURadio version 3.7.11 installed by the Linux Mint package manager in…
fleetingbytes
  • 2,512
  • 5
  • 16
  • 27
116
votes
7 answers

Python - add PYTHONPATH during command line module run

I want to run: python somescript.py somecommand But, when I run this I need PYTHONPATH to include a certain directory. I can't just add it to my environment variables because the directory I want to add changes based on what project I'm running. Is…
orokusaki
  • 55,146
  • 59
  • 179
  • 257
113
votes
6 answers

PYTHONPATH vs. sys.path

Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory. We have a Python project with a typical directory structure: Project setup.py …
new name
  • 15,861
  • 19
  • 68
  • 114
97
votes
4 answers

How do I import a Python script from a sibling directory?

Let's say I have the following directory structure: parent_dir/ foo_dir/ foo.py bar_dir/ bar.py If I wanted to import bar.py from within foo.py, how would I do that?
Orcris
  • 3,135
  • 6
  • 24
  • 24
94
votes
3 answers

Why use sys.path.append(path) instead of sys.path.insert(1, path)?

Edit: based on a Ulf Rompe's comment, it is important you use "1" instead of "0", otherwise you will break sys.path. I have been doing python for quite a while now (over a year), and I am always confused as to why people recommend you use…
Garrett Berg
  • 2,585
  • 1
  • 22
  • 21
90
votes
11 answers

How to configure custom PYTHONPATH with VM and PyCharm?

I am using IntelliJ with the Python plugin and the Remote Interpreter feature to communicate with my Vagrant VM. It sets up the remote interpreter correctly to use my VM's interpreter. But, I use a custom PYTHONPATH in my VM, and I would like…
baalexander
  • 2,579
  • 1
  • 25
  • 32
86
votes
2 answers

Effect of using sys.path.insert(0, path) and sys.path(append) when loading modules

I was recently having a problem with a python ImportError, where the module was found when running on my local computer but not found on the CI server. I solved this problem by swapping sys.path.append(path) in my script with sys.path.insert(0,…
Michael Barton
  • 8,868
  • 9
  • 35
  • 43
85
votes
7 answers

sys.path different in Jupyter and Python - how to import own modules in Jupyter?

In Jupyter my own little module is not loaded but in python/bpython is everything is fine. When typing import sys print(sys.path) the path to my module will not in show in Jupyter but in python/bpython it is still there. I am using: PYTHONPATH in…
ulf
  • 1,159
  • 1
  • 8
  • 6
81
votes
6 answers

How to get the PYTHONPATH in shell?

debian@debian:~$ echo $PYTHONPATH /home/qiime/lib/: debian@debian:~$ python Python 2.7.3 (default, Jan 2 2013, 16:53:07) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>>…
showkey
  • 482
  • 42
  • 140
  • 295
1
2 3
50 51