Questions tagged [pythonpath]
PYTHONPATH is an environment variable that can be used to augment the default search path for module imports in Python.
pythonpath
771
questions
527
votes
10
answers
1.1m
views
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)?
477
votes
24
answers
2.0m
views
How to add to the PYTHONPATH in Windows, so it finds my modules/packages? [duplicate]
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 ...
470
votes
24
answers
1.2m
views
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 ...
334
votes
36
answers
481k
views
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\
...
207
votes
34
answers
385k
views
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 ...
193
votes
6
answers
518k
views
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 ...
142
votes
13
answers
278k
views
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 ...
125
votes
7
answers
210k
views
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 ...
118
votes
6
answers
145k
views
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 ...
106
votes
5
answers
67k
views
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?
96
votes
3
answers
145k
views
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 ...
93
votes
2
answers
273k
views
Effect of using sys.path.insert(0, path) and sys.path.append(path) 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....
91
votes
11
answers
148k
views
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 ...
91
votes
7
answers
206k
views
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/...
86
votes
6
answers
343k
views
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 "...
83
votes
2
answers
198k
views
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 &...
82
votes
7
answers
74k
views
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 ...
78
votes
8
answers
430k
views
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 ...
77
votes
3
answers
445k
views
PYTHONPATH on Linux [closed]
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 ...
77
votes
4
answers
66k
views
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?
69
votes
4
answers
94k
views
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; ...
67
votes
4
answers
91k
views
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 ...
63
votes
14
answers
64k
views
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 ...
53
votes
6
answers
107k
views
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 ...
52
votes
18
answers
201k
views
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 (...
51
votes
4
answers
48k
views
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-...
40
votes
4
answers
22k
views
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
├...
36
votes
4
answers
9k
views
Best practice for reusing python code [closed]
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 ...
34
votes
9
answers
203k
views
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 ...
33
votes
8
answers
20k
views
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 ...
31
votes
3
answers
17k
views
Python: sharing common code among a family of scripts
I'm writing a family of Python scripts within a project; each script is within a subdirectory of the project, like so:
projectroot
|
|- subproject1
| |
| |- script1.main.py
| `- ...
30
votes
1
answer
19k
views
Import parent directory for brief tests
I have searched this site top to bottom yet have not found a single way to actually accomplish what I want in Python3x. This is a simple toy app so I figured I could write some simple test cases in ...
30
votes
4
answers
26k
views
Python: select one of multiple installed module versions
On my system, I have several modules installed multiple times. To give an example, numpy 1.6.1 is installed in the standard path at /usr/lib/python2.7/dist-packages, and I have an updated version of ...
27
votes
5
answers
19k
views
Module name different than directory name?
Let's assume I have a python package called bestpackage.
Convention dictates that bestpacakge would also be a directory on sys.path that contains an __init__.py to make the interpreter assume it can ...
26
votes
6
answers
28k
views
PYTHONPATH not working for sudo on GNU/Linux (works for root)
EDIT: Works for root, sudo is the problem. Read below.
I have a directory with my own libraries, e.g. my Python libraries are located at /home/name/lib/py.
I've added this directory to Python's PATH ...
26
votes
2
answers
54k
views
How to add something to PYTHONPATH?
I downloaded a package (called pysolr 2.0.15) to my computer to be used with Haystack. The instructions asks me to add pysolr to my PYTHONPATH.
What exactly does that mean? After extracting the ...
25
votes
1
answer
42k
views
What to set `SPARK_HOME` to?
Installed apache-maven-3.3.3, scala 2.11.6, then ran:
$ git clone git://github.com/apache/spark.git -b branch-1.4
$ cd spark
$ build/mvn -DskipTests clean package
Finally:
$ git clone https://...
25
votes
3
answers
14k
views
Set PYTHONPATH for local Jupyter Notebook in VS Code
I'm using Visual Studio 1.39.2 on Windows 10. I'm very happy that you can run Jupyter Notebook natively through VS Code as of October this year (2019), but one thing I don't get right is how to set my ...
24
votes
3
answers
38k
views
How to import multiple locations to PYTHONPATH (bash)
I know you can add multiple locations to python path by separating them by colons ie:
export PYTHONPATH=~/one/location:~/second/location
etc.
I have several locations to add and it looks messy ...
22
votes
2
answers
11k
views
Creating a secondary site-packages directory (and loading packages from .pth files therein)
I would like to install some packages into a third-party site-packages directory (beyond the standard system locations). Is there any way to set this up such that .pth files therein are respected?
...
21
votes
7
answers
12k
views
How to properly structure internal scripts in a Python project?
Consider the following Python project skeleton:
proj/
├── foo
│ └── __init__.py
├── README.md
└── scripts
└── run.py
In this case foo holds the main project files, for example
# foo/__init__....
20
votes
3
answers
38k
views
pip won't install Python packages locally with --user
I'm trying to install packages locally with pip. It used to work with --user but now when I try it, it finds the version of the package in /usr/local/lib/ and then does not install it locally. ...
20
votes
3
answers
746
views
Why does heroku local:run wants to use the global python installation instead of the currently activated virtual env?
Using Heroku to deploy our Django application, everything seems to work by the spec, except the heroku local:run command.
We oftentimes need to run commands through Django's manage.py file. Running ...
18
votes
2
answers
19k
views
How to setup PyCharm for multiple projects
I want to set up PyCharm to work on a set of Python projects in a single window.
Lets say I have this projects structure.
~/src
├── py_project1
├── py_project2
├── py_project3
├── other_lang_proj1
└── ...
16
votes
5
answers
51k
views
permanently remove directory from python path
I recently added some things to my python path that I don't want there using:
export PYTHONPATH=$PYTHONPATH:/my/path
You can use sys.path.remove to remove something in the path, but it's not 100% ...
16
votes
3
answers
8k
views
Force import module from Python standard library instead of PYTHONPATH default
I have a custom module in one of the directories in my PYTHONPATH with the same name as one of the standard library modules, so that when I import module_name, that module gets loaded. If I want to ...
14
votes
5
answers
55k
views
Installed module using pip, not found
I am trying to install a package called "simpleguitk" via pip. (On Ubuntu 16.04 with Python 3.5)
After running
sudo -H pip3 install simpleguitk
it says installation is completed successfully. (...
14
votes
2
answers
27k
views
Python packages with conflicting dependencies
we are trying to install several own written python3 applications sharing some libraries with conflicting versions.
We are currently discussing employing the order of packages inside the PYTHONPATH ...
14
votes
5
answers
3k
views
PYTHONPATH order on Ubuntu 14.04
I have two computers running Ubuntu 14.04 server (let's call them A and B). B was initially a 10.04 but it has received two upgrades to 12.04 and 14.04. I do not understand why the python path is ...
12
votes
4
answers
26k
views
Apache with virtualenv and mod_wsgi : ImportError : No module named 'django'
I'm trying to serve a little django project with the following Apache configuration :
Apache virtualhost configuration :
<VirtualHost *>
ServerName servername
[...]
<Directory ...