Question

I have tried to add a permanent directory from here but i didn't understand how to do it. The answer states that:

You need to add your new directory to the environment variable PYTHONPATH, separated by a colon from previous contents thereof.

However I pressed the Windows_Start Button and the Pause/Break Button and in Advanced System Settings I went to Environment Variables

AND HERE'S THE PROBLEM

There is no Variable named PYTHONPATH to set-up a value there!!! It must be a bug!

These are the values that exist in my System variables

ComSpec
FP_NO_HOST_CHECK
NUMBER_OF_PROCESSORS
OS
Path
PATHEXT
PROCESSOR_ARCHITECTURE
PROCESSOR_IDENTIFIER
PROCESSOR_LEVER
PROCESSOR_REVISION
PSModulePath
TEMP
TMP
USERNAME
windir
windows_tracing_flags
windows_tracing_logfile

See my problem is that i use sys.path.append() to add the directory but once i restart the GUI i must re-input the command.

The solution aforementioned and linked states that i must find the PYTHONPATH and add the directory there but i have no Environment Variable named PYTHONPATH

How can i run around this problem?

EDIT

Create a file start-my-app.cmd using a text editor (Notepad is good, Word/Wordpad is bad). Copy the code above and replace the parts between ... with what you need. Double click start-my-app.cmd or type start-my-app.cmd in a command prompt (you need to be in the same folder as start-my-app.cmd for this to work). – Aaron Digulla

-->Like this

enter image description here

THIS IS HOW I DID IT. IS IT CORRECT? PLZ TELL ME

  1. Go to Environment Variables
  2. Click the New Button in System Variables
  3. Fill in the variable details

It looks suspiciously easy to me in contrast to the answers i have received but it works and every time i open the GUI i dont have to append the path. If there is anything wrong with this solution plz tell me.

Thank you

Was it helpful?

Solution

You can create a new one; the comment above only means: "If there already is one, don't just overwrote the current value".

That said, I don't like changing global environment variables much. First of all, you must not forget to restart all command prompts because existing ones don't get new variables.

My preferred solution is to create a .cmd/.bat file which contains:

set PYTHONPATH=...whatever your code needs...

python ...and start your Python code here...

That way the variable will be there when you expect it, no matter when and from where you start the script and it will not interfere with other stuff that you might also have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top