This question already has answers here:
Dealing with multiple Python versions and PIP?
(28 answers)
Closed 5 years ago.
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:
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.
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.
Related
Versions:
Python: 3.10.4
Pylint: 2.15.3
Visual Studio Code: 1.72.2
The .pylintrc file was generated using
pylint --generate-rcfile
command.
It has the following option configured:
[METHOD_ARGS]
# List of qualified names (i.e., library.method) which require a timeout
# parameter e.g. 'requests.api.get,requests.api.post'
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
However I see an error which sounds:
Unrecognized option found: timeout-methods Pylint(E0015:unrecognized-option)
The documentation states that option timeout-methods is supported: https://pylint.pycqa.org/en/latest/user_guide/configuration/all-options.html#timeout-methods.
So I am lost why do I have that error displayed by pylint in visual studio code.
As the comments under the original code showed, the pylint version bundled in the VS Code extension and the one that was used to generate the .pylintrc file differ.
Normally, the VS Code Pylint extension should use the pylint version installed in the Python environment that you configured to use for your project, and only falls back to the bundled version if no other pylint version was found. See also the extension docs for details.
Check the following:
Make sure that you configured the correct Python environment for your project. See Select a Python interpreter in the docs.
Make sure that you have installed pylint in the Python environment you have configured for your project, and are not accidentally using a pylint installation from your global Python environment. After configuring the Python interpreter (see step 1), once you open a new terminal in VS Code this environment should be activated by default. Run pip list | grep pylint (macOS/Linux) or pip list | findstr pylint (Windows) to check if pylint is installed.
If both 1 & 2 are fulfilled and you still have problems, check if pylint.importStrategy is maybe set to useBundled in your VS Code settings.json, and remove it or set it to fromEnvironment.
pylint 2.15 take this option into account correctly. But it was released only 2 month ago. Your error must come from the pylint version included in visual studio code that might lag a little behind and do not handle it yet.
I realise that there is already an answer for the question but its for Mac OS X 10.6.4 and the python he installed was from "python.org". My python 2.7 has come built-in in my Mac so how do I remove it? Is there any way of removing it? I have installed a python3.7 from the website and it is working perfectly but 2.7 is also working. I want to remove 2.7 and make it such that when i type "python" in terminal it runs python3.7 and not 2.7.
You don't have to remove python 2.7. You can simply add the command as an alias (you can also add this in your ~/.bash_profile file):
alias python='python3.7'
Do not remove python 2.7 (default python package), it may damage your operating system.
If you want you can simply use this command (removes the python installed with homebrew):
brew uninstall python
Refer this question if you really thinking of removing python 2.7. Here is another question which will give you more information.
the 2.7 version of python is a bundle that comes along with the MAC Unix operating system. which means maybe you not using it but there are some pre-loaded programs and dependencies which uses python hence you cannot remove it completely. If you want to use python 3 directly from the terminal's command line just use "python3" in place of "python". this will launch python 3.* what ever you have installed.
A Mac has more Pythons than a Malaysian jungle.
A new Mac M1 has version 2.7 in /System/Library/Frameworks/Python.framework/Versions/2.7
If you use Homebrew to install Vim, it uses /opt/homebrew/Cellar/python#3.9, and it warns you if you delete it, Vim won't work.
Meantime, I want to do the introductory tensorflow machine learning course, and it insists on Python 3.8
So in my .bash_profile
alias python='/opt/homebrew/Cellar/python#3.8/3.8.8_1/bin/python3'
alias python3='python'
alias python3.8='python3'
and I deleted all references to Python2.7.
But when I open a new terminal, and run a Python program which does
print(sys.path)
it includes /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
and tensorflow won't work. The Mac is inserting its own Python into what I want.
I am trying to install cx_Freeze==5.0.2 on Windows 8.1 / Python 3.7 but I am getting this Error:
I do not know what exactly cx_Freeze is for or why i need this version - it is from a requirements text file that threw and error, and this module is the only one that i could not install manually.
It says something about Visual C++ above, but I do have it installed, so I dont know why its saying that.
cx_Feeze needs compiling to run (this is usually done for you on Windows but it has not been done for 3.7 yet (see the releases on PyPi) so you have two options:
Wait until it is (shouldn't be more than a few days/weeks, it wasn't last time python updated in any case)
Compile it yourself
In the case of compiling, if you have VS installed then you probably have not set the correct environment variables
SET DISTUTILS_USE_SDK=1
SET MSSdk=1
Taken from here.
I would recomend the answers in this question over the duplicate suggested above.
I had two version of python.. python 2.6 and python 2.7
I just now deleted python 2.6 (rather in very unsafe way)..
Now when I type python, I get this error:
python: VERSIONER_PYTHON_VERSION environment variable error (ignored)
python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: No such file or directory
My python 2.7 is installed in
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
When i do which python
I get /usr/bin/python
How do i resolve this mess I have created.
Looks like you deleted the Apple-supplied Python 2.6. You shouldn't have done that. Never delete files in /usr, other than /usr/local, or in /System/Library. When you install another framework version of Python, like you did with the Python 2.7 into /Library/Frameworks, the way to manage which one you use is by managing your shell PATH environment variable, not by attempting to modify /usr/bin/python. You have three primary options now: (1) live without the Apple-supplied Python 2.6 until your next OS X upgrade and hope that no other Apple-supplied utilities you need depend on it; or (2) reinstall all of OS X; or (3) if you remember exactly what you deleted and have a full backup, attempt to restore the deleted files. To use the newer Python 2.7, put it first on your path, for example:
export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
I've been using python 2.7 and after installation of python 2.7. All of the scripts have run successfully, but suddenly today, when I run python, it is recognized with python 2.6, so for one of the python packages I get the following error:
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python:
No module named htseq-count
i am not sure why it happens. The path environment variable for python is set to:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/Resources/bin:${PATH}" export PATH
How do I fix this error?
If your code relies on a particular version of Python, you should specify python2.7 or python2.6 instead of just python.
If this "suddenly" happened it's possible that installing some other software modified your $PATH so that the old version of Python now has priority (it's possible for multiple versions to be on your $PATH; it uses the first one it finds).
If you move these two lines to the bottom of the file they're in (maybe ~/.profile) it may correct this.
PATH="/Library/Frameworks/Python.framework/Versions/2.7/Resources/bin:${PATH}"
export PATH
You can type which python in Terminal you can see what binary it finds when looking for python on your $PATH.
If you don't mind using Python 2.6, you can probably install the missing package by typing this in your terminal:
easy_install-2.6 htseq
I think you are applying different python version to be used.
type
which python
under your control.
see which python you are using, you should config the one using python 2.7
python --version