0

I've just started a class that uses Python. At this point, I'm a complete beginner. I running Windows 10 via Parallels on an iMac. I'm have trouble organizing the directories within the "Python36-32" directory that is located on the VM (Windows). If I place a .py file in the main directory, I can run the file through the command prompt and see something like.

c:\Program Files\Python36-32>python first.py hello

However, if I try to organized the file the file isn't read at all. For example, if I wanted the "first.py" file to run from a "web221" (the name of my class) subdirectory of "python36-32" and then try to open "first.py", I get:

C:\Program Files\Python36-32\web221>python first.py 'python' is not recognized as an internal or external command, operable program or batch file.

I'd really like to keep all of the .py files I create for my class organized for obvious reasons. Any help would be appreciated.

rstaad
  • 1
  • 3
    can you confirm that python is in your PATH? – arcee123 Apr 03 '17 at 20:06
  • 3
    Why are you running Python in a Windows VM? Python is already installed on your Mac, and will be much easier to use there. – Daniel Roseman Apr 03 '17 at 20:07
  • There's probably a windows element to his class, and this would make it easier to keep up with rest of it. – TehTris Apr 03 '17 at 20:08
  • @arcee123 yes, python is in my PATH – rstaad Apr 04 '17 at 16:22
  • @DanielRoseman my course requires me to run Python on Windows. It's a Java programming class and the material is setup using the command prompt I guess. I'd much rather keep it all on my Mac. – rstaad Apr 04 '17 at 16:23
  • Note that you shouldn't be creating your scripts *inside* Python's installation directory. That's especially wrong when Python is installed in the system directory `C:\Program Files`. Create your own directory for your Python scripts, e.g. a directory you create in the drive root like `C:\Python` or some directory in your profile, where you have full control. – Eryk Sun Apr 05 '17 at 17:11

1 Answers1

0

When you execute from the one directory, the Python executable is present and Windows has no issue finding what to execute.

From the other directory though, Windows attempts to find the executable in your PATH and cannot see it.

Here is some help from the Python 3 docs: https://docs.python.org/3/using/windows.html#excursus-setting-environment-variables

Specifically, try this as a test:

Windows allows environment variables to be configured permanently at both the User level and the System level, or temporarily in a command prompt.

To temporarily set environment variables, open Command Prompt and use the set command:

C:\>set PATH=C:\Program Files\Python 3.6;%PATH%
C:\>set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
C:\>python

However, this will only temporarily add the executable to your path. Try it to see if it works, and if it does, then you'll have the information you need to add it to your PATH variable permanently. Note: your directory is named differently, so you'll need to replace Python 3.6 with the name of the directory where Python is installed.

For the task of editing the PATH such that the changes persist from one command prompt session to the next, there's a related SO question that might be helpful: How to add to the pythonpath in windows 7?

Community
  • 1
  • 1
  • Thanks. I went through the process you provided but after hitting "Enter" at the end of the last command prompt, Python just opened within the Command Prompt window. I'm not sure what this means. – rstaad Apr 04 '17 at 16:37
  • Do you mean that an interactive shell was launched? Generally it'll print a bunch of info about what version of Python is running, followed by a >>> prompt. This is what happens when you invoke "python" by itself. Try running the "python first.py" inside the "web221" directory, as you did before. Hopefully it should work after setting the Python executable in your path. – DiphthongException Apr 04 '17 at 17:29