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
80
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
  • 1,097
  • 2
  • 8
  • 14
77
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
  • 39,921
  • 24
  • 98
  • 123
76
votes
8 answers

Add to python path mac os x

I thought import sys sys.path.append("/home/me/mydir") is appending a dir to my pythonpath if I print sys.path my dir is in there. Then I open a new command and it is not there anymore. But somehow Python cant import modules I saved in that…
MacPython
  • 17,901
  • 10
  • 42
  • 48
74
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,867
  • 7
  • 38
  • 57
73
votes
3 answers

PYTHONPATH on Linux

I'm novice in this, and I have started learning Python, but I have some questions that I'm not be able to understand, What exactly is the PYTHONPATH (on Ubuntu)? Is it a folder? Is Python provided by default on Ubuntu, or does it have to be…
user2580401
  • 1,840
  • 9
  • 28
  • 35
66
votes
4 answers

Anaconda: Permanently include external packages (like in PYTHONPATH)

I know how to install packages in Anaconda using conda install and also how to install packages that are on PyPi which is described in the manual. But how can I permanently include packages/folders into the PYTHONPATH of an Anaconda environment so…
Cord Kaldemeyer
  • 6,405
  • 8
  • 51
  • 81
66
votes
3 answers

python - os.getenv and os.environ don't see environment variables of my bash shell

I am on ubuntu 13.04, bash, python2.7.4 The interpreter doesn't see variables I set. Here is an example: $ echo $A 5 $ python -c 'import os; print os.getenv( "A" )' None $ python -c 'import os; print os.environ[ "A" ]' Traceback (most recent call…
xealits
  • 4,224
  • 4
  • 27
  • 36
62
votes
13 answers

ERROR: virtualenvwrapper could not find virtualenv in your path

I'm trying to create a virtualenv with virtualenvwrapper, but when I use mkvirtualenv I get the following : ERROR: virtualenvwrapper could not find virtualenv in your path I assumed it was a PYTHONPATH problem. But if I do a pip show virtualenv I…
vmonteco
  • 14,136
  • 15
  • 55
  • 86
50
votes
4 answers

how to set different PYTHONPATH variables for python3 and python2 respectively

I want to add a specific library path only to python2. After adding export PYTHONPATH="/path/to/lib/" to my .bashrc, however, executing python3 gets the error: Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python…
Douglas Su
  • 3,214
  • 7
  • 29
  • 58
49
votes
16 answers

No module named django but it is installed

I have two versions of python 2.7 and 3.4 and installed django through pip. it shows in ubuntu terminal: $ pip freeze Django==1.6.11 $ pip --version pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7) $ python Python 2.7.9 (default, Feb 3…
srk
  • 599
  • 1
  • 6
  • 17
48
votes
6 answers

Add directory to Python path in PyCharm?

I want to be able to use the paraview.simple library in PyCharm. I already have paraview installed in my computer. This package cannot be installed with pip and there are no .whl files as far as I can tell. The website docs recommend that the…
user32882
  • 5,094
  • 5
  • 43
  • 82
39
votes
3 answers

Customize module search path (PYTHONPATH) via pipenv

I have a Python project consisting of a Jupyter notebook, several scripts in a bin directory and modules in a src directory, with dependencies in a Pipfile: myproject ├── myproject.ipynb ├── Pipfile ├── Pipfile.lock ├── bin │   ├── bar.py │   └──…
David Moles
  • 48,006
  • 27
  • 136
  • 235
36
votes
4 answers

Best practice for reusing python code

I have write a python library app(which contains several *.py files). And several of my python projects need to reuse the code in the library app. What's the recommended best practice for reusing python code? Currently I have thought out three…
Tyler Liu
  • 19,552
  • 11
  • 100
  • 84
34
votes
9 answers

Import Error: No module named django

I am using centos linux. I had python 2.6 with django and now i upgraded to python 2.7. Python 2.6 is located in /usr/lib/python2.6. Python 2.7 is located in /usr/local/lib/python2.7. They both have site-packages directory and they both contain…
yossi
  • 12,945
  • 28
  • 84
  • 110
33
votes
8 answers

How to prepend a path to sys.path in Python?

Problem description: Using pip, I upgraded to the latest version of requests (version 2.7.0, with pip show requests giving the location /usr/local/lib/python2.7/dist-packages). When I import requests and print requests.__version__ in the interactive…
max
  • 339
  • 1
  • 3
  • 3
1
2
3
50 51