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

In this tutorial, we will learn How to add to the PYTHONPATH in Windows, so it finds my modules/packages, which we need to do though opening the environment variable and adding the location address to the ‘PATH’ of it. To do the same we need to follow certain steps and to do so we need to follow the instructions given below.

PYTHONPATH

PYTHONPATH Editing

To add the location of the python- pip folder to the Path of environment variable we need to follow the following steps

  1.  Open the ‘Environment variable’ either by simply typing it in a window or may also open in through the control panel which is a way to edit the system Setting.
  2.  A new dialog box would have popped up where we need to click the button advanced tab and click on the internment option.Control pannal
  3. Now we can see another dialog box where we need to click on ‘SystemVariable’ and there we need to scroll it down to the tab ‘Path’.
  4. After clicking the tab path we need to click on edit under the path tab, And then we need to click on the new bottom at the right side of the dialog box where we can will see a completely new blank line below all the lines. (Those lines are also the paths of some different software like MongoDB and all that we might be using and some are for the system itself) So,
    We need to keep in mind that we do not edit any of them otherwise some other functions may be affected.
  5. Now Past the address of the pip folder which we have copies from the python folder where we installed it in our system.
  6.  And finally, we have to click on the ‘Ok’ buttons of all the dialog boxes to close all of them as we had done our job of adding the path.

Alternatively, We can also do the same through the sys module and pass a command which is given below:

import sys
sys. path. append("/ path/ to/ my/ modules")

import mymodule

It will also add the path “/path/to/my/modules” to the path when we run the code given above.

Provided the second method does not work at times when it does not allow the import or we can say it works only for current python sessions.

 

To learn more about How to add to the PYTHONPATH in Windows, so it finds my modules/packages visit:  adding the path to the Environment variables

To learn more about python solutions to problems and tutorials of different python concepts visit: Python Tutorials And Problems.

To learn more about different other programming languages visit: beta python for programing Solutions.

Leave a Comment

%d bloggers like this: