Python search path (on Windows)

W

wooly booly

I would like to execute a Python script from Windows command line:

Python myscript.py

This works if myscript.py resides in the current folder. My question is:
Is it possible to execute the command above from another folder?

I put the script's folder in the PYTHONPATH environment variable but this
didn't help.

Thanks for your help!
 
G

Gabriel Genellina

I would like to execute a Python script from Windows command line:

Python myscript.py

This works if myscript.py resides in the current folder. My question is:
Is it possible to execute the command above from another folder?

Yes, use:
python path\to\the\actual\location\of\myscript.py
I put the script's folder in the PYTHONPATH environment variable but this
didn't help.

No, PYTHONPATH contains the directories searched when trying to import a
module -- it's not used to locate the main script.
 
D

Diez B. Roggisch

wooly said:
I would like to execute a Python script from Windows command line:

Python myscript.py

This works if myscript.py resides in the current folder. My question is:
Is it possible to execute the command above from another folder?

I put the script's folder in the PYTHONPATH environment variable but this
didn't help.

Then you could try

Python -m myscript

Diez
 
A

Ant

I would like to execute a Python script from Windows command line:

Python myscript.py

This works if myscript.py resides in the current folder. My question is:
Is it possible to execute the command above from another folder?

I put the script's folder in the PYTHONPATH environment variable but this
didn't help.

Thanks for your help!

You can put the script directory in the PATH environment variable, and
call it with just:

myscript.py
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,275
Messages
2,571,381
Members
48,070
Latest member
nick_tyson

Latest Threads

Top