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.

676 questions
404
votes
9 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
  • 89,393
  • 53
  • 186
  • 261
399
votes
22 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
  • 17,033
  • 16
  • 55
  • 79
356
votes
20 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
  • 50,339
  • 21
  • 44
  • 63
303
votes
15 answers

How do you properly determine the current script directory?

I would like to see what is the best way to determine the current script directory in Python. I discovered that, due to the many ways of calling Python code, it is hard to find a good solution. Here are some problems: __file__ is not defined if the…
bogdan
  • 7,114
  • 10
  • 35
  • 42
237
votes
27 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
  • 51,372
  • 47
  • 157
  • 214
193
votes
29 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,698
  • 4
  • 25
  • 36
150
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,695
  • 2
  • 12
  • 14
97
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 …
gaefan
  • 14,322
  • 16
  • 52
  • 100
96
votes
5 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
  • 48,267
  • 47
  • 159
  • 244
91
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,475
  • 1
  • 18
  • 18
86
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,531
  • 1
  • 25
  • 32
70
votes
2 answers

set pythonpath before import statements

My code is: import scriptlib.abc import scriptlib.xyz def foo(): ... some operations but the scriptlib is in some other directory, so I will have to include that directory in environment variable "PYTHONPATH". Is there anyway in which I can…
DKG
  • 997
  • 2
  • 7
  • 14
69
votes
6 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
  • 889
  • 1
  • 7
  • 5
67
votes
7 answers

Where to put a configuration file in Python?

In development mode, I have the following directory tree : | my_project/ | setup.py | my_project/ | __init__.py | main.py | conf/ | myproject.conf I use ConfigParser to parse the myproject.conf file. In my code, it's easy to…
Sandro Munda
  • 36,427
  • 21
  • 94
  • 117
64
votes
4 answers

How does python find a module file if the import statement only contains the filename?

Everywhere I see Python code importing modules using import sys or import mymodule How does the interpreter find the correct file if no directory or path is provided?
Asciiom
  • 9,409
  • 7
  • 35
  • 57
1
2 3
45 46