-1

Python35-32 is installed on my PC running Windows 7 64-bit, in the directory ‘C:/Program Files (x86)/Python35-32’.

My Python scripts are installed in:

C:/Program Files (x86)/Python35-32/Scripts/pyscripts

The System Environment Variable ‘Path’ includes:

C:/Program Files (x86)/Python35-32’

and:

C:/Program Files (x86)/Python35-32/Scripts/pyscripts

The System Variable ‘PATHEXT ‘ is:

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY

The User Environment Variable ‘PATH’ is:

C:/Program Files (x86)/Python35-32;C:/Program Files (x86)/Python35-32/Scripts/pyscripts

The Python current working directory is;

C:/Program Files (x86)/Python35-32

There are several scripts in the directory ‘pyscripts’: ‘CleanupStops.py’ and ‘concord.py’ are two of them.

Upon entering the following at the Python prompt:

>>> CleanupStops.py`

The following error message is returned;

Traceback (most recent call last):
        File “<stdin>”, line 1, in < module.
NameError: name ‘CleanupStops’ is not defined
Invoking another script results in the same error message.

I can run the scripts from PowerShell if I change the current working directory to C:/Program Files (x86)/Python35-32/Scripts/pyscripts.

I have researched similar issues which were resolved by:

  1. Inserting the correct path into the environment variables
  2. Including the file extension .py and/or
  3. Changing the current working directory to where the scripts are located.

I have incorporated these, but still receive a NameError as described above.

I would also like to run python scripts from PowerShell without having to change the current working directory every time I open PowerShell. I have not found advice on how to do this. How do I resolve these problems?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
RJS
  • 139
  • 1
  • 13

2 Answers2

0

You need to add your scripts folder to the PYTHONPATH environment variable to allow calling scripts in python from any location How to add to the pythonpath in windows 7?

Community
  • 1
  • 1
BenJ
  • 456
  • 2
  • 7
  • thanks for the suggestion; I have done that but continue to get the NameError message – RJS Feb 01 '16 at 16:11
  • Hmmm... maybe just confirm the environment variables are correctly configured in PowerShell https://technet.microsoft.com/en-us/library/ff730964.aspx Does it work in regular windows command prompt? – BenJ Feb 01 '16 at 22:12
0

Are you running two versions of python?

I would use a batch file. To try

SET PATH=%PATH%;c:\the\location

python file_name.py

pause

I'd use pause just to see if it works. Remove it if that works.

user5823815
  • 161
  • 6