5

I've installed django using the pip command (pip install Django), but i can't run it using the py command, as it can't find the module. I can only make it works using 'python' command.

Here is a summary of the screenshot I have atttached

$ python --version
Python 3.6.1
$ py --version
Python 3.6.0

It also looks like django works only with 3.6.1.

Is there any way to set both commands to run newest version of python?

Screenshot:

screen

5
  • What is your operating system?
    – Evan
    Commented Sep 3, 2017 at 19:15
  • type which python and which py and post your results. I have found that on my windows pc these commands are from different python installation. Packaes like django are specific to a python install or virtual environment.
    – tread
    Commented Sep 3, 2017 at 19:17
  • 1. @Evan - Win10Pro 64-bit 2. @surfer190 - these which python and which py command are not recognized as commands in my prompt
    – Taki Nikt
    Commented Sep 3, 2017 at 19:35
  • Try where (Windows) instead of which (Linux). Commented Sep 3, 2017 at 23:56
  • It may be that the 3.6.1 installation is 32-bit, and the 3.6.0 installation is 64-bit. The launcher prefers 64-bit builds over 32-bit builds for a given major.minor version. The micro release number (i.e. major.minor.micro) is ignored here.
    – Eryk Sun
    Commented Sep 4, 2017 at 4:16

2 Answers 2

2

You're using Python launcher for Windows when you executepy. You could be specific about which Python interpreter version that you want py to execute with this command:

> py -3.6

See this section from PEP 397: Python Version Qualifiers

If no version qualifiers are found in a command, the environment variable PY_PYTHON can be set to specify the default version qualifier - the default value is "2". Note this value could specify just a major version (e.g. "2") or a major.minor qualifier (e.g. "2.6"), or even major.minor-32.

If no minor version qualifiers are found, the environment variable PY_PYTHON{major} (where {major} is the current major version qualifier as determined above) can be set to specify the full version. If no such option is found, the launcher will enumerate the installed Python versions and use the latest minor release found for the major version, which is likely, although not guaranteed, to be the most recently installed version in that family.

In addition to environment variables, the same settings can be configured in the .INI file used by the launcher. The section in the INI file is called [defaults] and the key name will be the same as the environment variables without the leading PY_ prefix (and note that the key names in the INI file are case insensitive.) The contents of an environment variable will override things specified in the INI file.

Plus Python launcher isn't just limited to launching different Python versions, it also parses shebang #! in source code files, providing a functionality similar to that in *nix operating systems in Windows.

*Refer to Python Launcher for Windows documentation.

1
  • @eryksun Thanks for the information. I included a reference to the doc page you've provided.
    – GIZ
    Commented Sep 9, 2017 at 13:33
1

On windows, py is an executable stored in the C:\Windows folder. I honestly don't know what it contains, as I am used to where it is a symbolic link on linux, and my windows install shows the normal python executable as being a fraction of the size of py, despite my being quite sure that they point to the same installation. Regardless, you can fix your problem by deleting or renaming (python.bak, etc) the executable you don't want to keep using from the Windows folder, then copying the one you want in place and renaming it to the same name that you previously deleted or renamed. I can't imagine this is the official way to fix this problem, but this will work. Also, in the future, feel free to specify the version you are installing to with pip explicitly if you want to be sure of which installation you are using instead of just running whatever points to pip:

py -m pip install packagename
python -m pip install packagename

Running into problems with multiple python versions on the same system is quite common with Windows, so setting up a virtual environment may be beneficial. This is explained in the Django Windows install how-to.

1
  • python.exe is not in the Windows folder, and nothing should be deleted or renamed. It's simply a matter of which version py.exe prefers, e.g. 64-bit 3.6 over 32-bit 3.6 vs the version the OP has in PATH. The problem can be resolved without resorting to such drastic measures.
    – Eryk Sun
    Commented Sep 9, 2017 at 1:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.