0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Well i type these commands (set PYTHONPATH...) in the cmd? And what is a .cmd/bat file? Can you expand a little bit your ansewer plz?
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).
Will it set it permanently? If i put the file in C:\Python27\pysec-master where the work is being done? Will i have to type start-my-app.cmd in the cmd in every time i start to work?
No, the variable exists only as long as the batch script is running. You now have to use this batch script to start the software instead of the original command.
Read this, it should answer at least half of your questions: superuser.com/questions/284342/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.