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

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

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:Python27Lib;C:Python27DLLs;C:Python27Liblib-tk;C:other-folders-on-the-path

enter

This is the best way that has worked for me which I hadnt 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.

Windows 7 Professional
I Modified @mongoose_zas 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:pathtopythonversion
    enter
  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%Liblib-tk;
    enter

  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.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *