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

python path windows 10
python environment variables
how to find python path
set python path
find python path windows
how to set python path variable in windows 10
set python path mac
windows 10 register python path

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 > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error:

Error: No module named coltrane

You know what has worked for me really well on windows.

My Computer > Properties > Advanced System Settings > Environment Variables >

Just add the path as C:\Python27 (or wherever you installed python)

OR

Then under system variables I create a new Variable called PythonPath. In this variable I have C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path

This is the best way that has worked for me which I hadn't found in any of the docs offered.

EDIT: For those who are not able to get it, Please add

C:\Python27;

along with it. Else it will never work.

How to add to the PYTHONPATH in Windows, so it finds my , How to add to the PYTHONPATH in Windows, so it finds my modules/packages? in python. by Farkhanda Athar (  Procedure to add PYTHONPATH in windows: Go to MY Computer icon then click on Properties > Advance system settings> Environment Variables. Click on the “new” button in the upper half of the dialog, to create a new variable for the user. The variable name is given as PYTHONPATH and the value represents the path to the code directory. Click Ok

Windows 7 Professional I Modified @mongoose_za's answer to make it easier to change the python version:

  1. [Right Click]Computer > Properties >Advanced System Settings > Environment Variables
  2. Click [New] under "System Variable"
  3. Variable Name: PY_HOME, Variable Value:C:\path\to\python\version
  4. Click [OK]
  5. Locate the "Path" System variable and click [Edit]
  6. Add the following to the existing variable:

    %PY_HOME%;%PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk;

  7. Click [OK] to close all of the windows.

As a final sanity check open a command prompt and enter python. You should see

>python [whatever version you are using]

If you need to switch between versions, you only need to modify the PY_HOME variable to point to the proper directory. This is bit easier to manage if you need multiple python versions installed.

3. Using Python on Windows, Unlike most Unix systems and services, Windows does not require Python has compiled Windows installers (MSI packages) with every release for many My Computer ‣ Properties ‣ Advanced ‣ Environment Variables To make this setting permanent, you could add the corresponding command line Found a bug? 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 > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the

From Windows command line:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

To set the PYTHONPATH permanently, add the line to your autoexec.bat. Alternatively, if you edit the system variable through the System Properties, it will also be changed permanently.

How to edit PYTHONPATH on Windows, And you would like to edit your PYTHONPATH permanently. Edit the file to include this line C:\\Users\\<your_username>\\my_ module If in the first place you are only looking to edit your path locally, this helpful answer will do. I just hope my 2 hours of frustration + 1 hour of writing this post saved you  PYTHONPATH also check which libraries accommodate imported modules. Procedure to add PYTHONPATH in windows: Go to MY Computer icon then click on Properties > Advance system settings> Environment Variables. Click on the “new” button in the upper half of the dialog, to create a new variable for the user.

Just append your installation path (ex. C:\Python27\) to the PATH variable in System variables. Then close and open your command line and type 'python'.

How to add Python Path to Environment Variables in Windows 10 , This video will show you how to set Windows 10 environment variables for Python. You can use Duration: 2:31 Posted: Jan 14, 2016 PYTHONPATH, if it exists, should contain directories that should be searched for modules when using import. If PYTHONPATH is set, Python will include the directories in sys.path for searching. Use a semicolon to separate multiple directories. Here is an example of setting the environment variable in Windows and listing the paths in Python:

These solutions work, but they work for your code ONLY on your machine. I would add a couple of lines to your code that look like this:

import sys
if "C:\\My_Python_Lib" not in sys.path:
    sys.path.append("C:\\My_Python_Lib")

That should take care of your problems

How to set python path, How do I set python path and other environment variables - In order to run Python Right-click 'My Computer'. How to add to the pythonpath in windows normal programs because Python knows where to find its standard library. So when you import modules in your Python scripts, PYTHONPATH is also looked into to  In order to have Python see the modules inside each subdirectory, add a blank file called __init__.py to each subdirectory (with two underscores on each side). Now to import the module and use a function called foo() do: from NewProject import MyModule as m

Using PYTHONPATH, Returning to the example module and script in Where does Python look for modules?: At the moment, on my machine, PYTHONPATH is empty: on Windows $ export PYTHONPATH="$PWD/code" $ # Now the script can find For example, let's say I wanted add the directory /Users/my_user/code to the PYTHONPATH:  So Python will find any packages that have been installed to those locations. How sys.path gets populated. As the docs explain, sys.path is populated using the current working directory, followed by directories listed in your PYTHONPATH environment variable, followed by installation-dependent default paths, which are controlled by the site module.

Add Python to the Windows Path, What are modules? Import modules · Find files on disk · Display module content; Strings; What are strings? Escape characters · Access individual characters  My own search only yielded a blog post about where to put version-independent pure Python packages and a SO question for the canonical location under Linux, while I am working on Windows. My use case is that I would like to be able to import my own packages during a IPython session just like any site-package, no matter in which working

The Module Search Path – Real Python, Course: Python Modules and Packages: An Introduction The list of directories contained in the PYTHONPATH environment variable, if it is set. So, to ensure that your module is found, you need to do one of the following: Put mod.py in the directory where the input script is located, or the current directory  You need to add your new directory to the environment variable PYTHONPATH, separated by a colon from previous contents thereof.In any form of Unix, you can do that in a startup script appropriate to whatever shell you're using (.profile or whatever, depending on your favorite shell) with a command which, again, depends on the shell in question; in Windows, you can do it through the system GUI

Comments
  • for "no module named" error: stackoverflow.com/questions/23417941/…
  • I used site module.
  • if you want to run python in command prompt it is answered well here I hope this helps stackoverflow.com/a/54618199/8253662
  • You probably want to add C:\Python27 in your path.
  • @SteveKoch I'm not sure — you would have to ask project's maintener. I no longer use Path Editor as I switched to much better Rapid Environment Editor
  • It's also important to add C:\Python27\Scripts to the path so that installed scripts can be run from the shell.
  • Why would you put C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk in PYTHONPATH? Those are already configured. Directories for scripts go in the system PATH. Directories for libraries (that aren't installed to site-packages or the per-user site-packages) go in PYTHONPATH.
  • I had to include %PYTHONPATH% in my PATH as well.
  • Tried this and it worked... i would recommend anyone going through the same problem to try this.
  • Tried this, it didn't do anything at all.
  • I tried the accepted answer above and that didn't work so I would recommend this one.