Skip to main content
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

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 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

Answer*

Cancel
6
  • 9
    I prefer to use set path=%PATH%;%PYTHONPATH%;
    Mr Wednesday
    –  Mr Wednesday
    2013-02-23 01:43:14 +00:00
    Commented Feb 23, 2013 at 1:43
  • 11
    Dos and editing autoexec.bat..! Have we suddenly slipped back into the 90s?
    C Mars
    –  C Mars
    2013-12-12 18:05:38 +00:00
    Commented Dec 12, 2013 at 18:05
  • 12
    Before this, do echo %PYTHONPATH% if this gives you a path go on, otherwise, do e.g. set PYTHONPATH=.;C:\My_python_lib If you don't, windows will expand %PYTHONPATH% to empty string as expected, it will keep it as %PYTHONPATH% in the PYTHONPATH and everything will break! Sounds crazy but thats how win7 cmd works...
    ntg
    –  ntg
    2017-11-10 12:19:46 +00:00
    Commented Nov 10, 2017 at 12:19
  • 2
    To make it permanent, use setx instead of set.
    Amit Naidu
    –  Amit Naidu
    2022-10-25 16:49:38 +00:00
    Commented Oct 25, 2022 at 16:49
  • 2
    Note that the syntax differs if using setx, per @AmitNaidu's suggestion - I think it would be setx PYTHONPATH %PYTHONPATH%;C:\My_python_lib or set PYTHONPATH .;C:\My_python_lib. And note that your path can't contain spaces (see e.g. stackoverflow.com/a/69246810/4659442)
    philipnye
    –  philipnye
    2023-08-28 15:16:07 +00:00
    Commented Aug 28, 2023 at 15:16

Morty Proxy This is a proxified and sanitized view of the page, visit original site.