Terminal can't find version of python despite it being installed - python

I'm trying to install packages on multiple versions of Python. I'm currently running 3.8.8, and 3.11.0.
Following this post Install a module using pip for specific python version
called
python3.11 -m pip install pandas
which results in
File "<stdin>", line 1 python3.11 -m pip install pandas SyntaxError: invalid syntax
This seems to indicate an issue with python, so I double checked that python3.11 is installed.
the python3.11 works in isolation seems to work.
I don't understand why the install command isn't working.

If you’re using Linux try just
python3 —-version
In Windows you may need to add path to folder with installed Python to PATH variable.

Check your environment variables, you could try removing the variables pointing to the 3.8 version until you get the packages you want installed.
You could also try navigating to that python 3.11 installation directly, and executing the python shell from there, then run the command.

Related

How to fix "Error: No module named mysql.connector"

I am working with some python program where I need to import mysql.connector. But I am facing ImportError: No module named connector. I already read answers on same issue and also explore google to find out and try some step to fix still it not fixed.
I am working on MacOS. and I guess by default python 2.7.18 is installed and also I installed python 3.8.9.
So I came to know that I have to install pip install mysql-connector for python 2.X but when I ran this in my terminal it is showing command not found: pip . Then I tried to install pip3 install mysql-connector. for python3 and it got successfully installed.
But Still problem not fixed. Any idea how to fix this?
It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.
By default, the Python extension looks for and uses the first Python
interpreter it finds in the system path. To select a specific
environment, use the Python: Select Interpreter command from the
Command Palette (Ctrl+Shift+P).
Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation:
https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment
You got two Python installed in your system. Python3 and Python2.
Pip3 is just for python3.
You must use pip2 or pip2.7 for work with python2.
Search if you got the pip2 package installed is not then install it.

Using VSCode on Mac, can't get Python 3.8 to run, only Python 2.7.16

I just downloaded VSCode on my Mac as well as Python and pip. I downloaded the latest version of Python via VS Microsoft extensions and installed pip using Python -m ensurepip --upgrade. I have python 2.7.16 on my Mac as well, I believe from my OS (it's not something I downloaded). I am trying to use pip and Python in VSCode. I have my interpreter in my virtual environment set to Python 3.8.2, and I created the virtual environment using "python3 -m venv .venv". However, every time I check the python version (with Python --version) in the terminal, it returns Python 2.7.16. I check the pip version, and there is no command found. When I check the pip3 version, I get back the following warning:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
You can invoke Python with '-m pip' instead of running pip directly to avoid this problem.
pip 21.3.1 from /Users/username/Library/Python/3.8/lib/python/site-packages/pip (python 3.8)
Whenever I run Python -m pip or Python -m pip3, it returns "no module named pip".
When installing Python, I got a warning that Python 3 was not on the PATH, but it did not fix the issue when I tried to add the path. Unfortunately, I don't have much experience adding a path so I may have done that incorrectly.
Finally, I installed streamlit via pip3. It resulted in the following message but seemed to install. However, it could not be resolved when I tried to import streamlit in my code.
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
You can invoke Python with '-m pip' instead of running pip directly to avoid this problem.
Defaulting to user installation because normal site packages is not writeable
How do I add Python 3 to my PATH and ensure that VSCode runs Python 3 instead of 2?
Simply always refer 'python3' rather than 'python'.
python3 --version
python3 -m pip install blahblahblah

How to uninstall Python 2.7 and keep Python 3.4?

I think my title is pretty self-explanatory.
I want to uninstall Python 2.7 and keep Python 3.4 intact. Is this easy to do? I found a couple of tutorials about how to uninstall Python, but I don't want to uninstall the entire thing. Also, I am running Spyder (Python 3.6). This should work just fine after I get rid of 2.7, right. The reason I am asking all of this is because I installed pandas_datareader and apparently it went to 2.7, but I really wanted it on 3.4. Finally, I'm assuming, after I unistall 2.7, and run this 'pip install pandas_datareader' it will go to 3.4, right.
I can't seem to control where the install goes.
Instead of using:
pip install <module>
you can use the following to install the module which will install it to python-3.x (as long as python points to your python-3.x directory in your PATH):
python -m pip install <module>
Or alternatively, you can use pip3 to install it directly to python-3.x.
To use pip3, you need to navigate to:
C:\path\to\python\Scripts\pip3
and then run it as:
pip3 install <module>
and it will be installed to python-3.x rather than python-2.x.
If you need to uninstall a Python just use Windows' Add/Remove programs and run the uninstaller for that specific version.
Later versions of Python include PyLauncher (py.exe) and install it to C:\Windows which is always in the path. Use it to control which Python to run and which pip to run if you have several installed. If you use this you won't have to add a specific version of Python or its Scripts directory (where pip.exe is) to your path.
Examples:
py -3 -m pip install <package> # Use latest Python 3 installed.
py -2 -m pip install <package> # Use latest Python 2.
py -3.3 # Run Python 3.3
py -2.7-32 # Run 32-Python 2.7 on a 64-bit OS.
py # Run default Python (usually latest 3.x)
The PY_PYTHON environment variable can override the default.
See also: Python Launcher for Windows

Fatal Error Using Pip

I have using Python 3.4 in my machine . I have installed the same machine Python 2.7 and do what necessary in Environment Path . In Python34 folder I have changed python.exe to python3.exe . I can use Python2.7 using python command and Python3.4 using python3 command.But there was an error usin pip :
Fatal error in launcher: Unable to create process using '"C:\Python3.4\python.exe" "C:\Python3.4\Scripts\pip.exe" install'
As you see pip still using python.exe . How can I solve this ?
I'll try to be as clear as I can here, the answer you've linked to in the comments above is specifically asking about being able to run multiple versions of python on the same machine, and being able to specify which version is used to run a script from the command line.
when python 3 is installed two executables are added to c:\Windows\ called py.exe and pyw.exe these are used by default when a python script is invoked by double clicking on it in explorer.
if no other command line arguments are set then these executables look inside the script for the shebang line which looks like #!python2 or #!python3.3 and direct the py (or pyw) executable to use that version of python to run the script, note that this could just be #!python which would use the first version found on the system (oldest first) also note that only 2 significant digits can be used (so you couldn't use #!python3.3.4). If no shebang line is found, the first version of python found will be used.
to use a specific version of python from the command line you would then have a couple of options, firstly you could specify the entire path to the python version you want, e.g. C:\Python33\python.exe scriptname.py or you can use flags.
To use a flag you would call py -3.3 scriptname.py which would call the python 3.3 interpreter and pass it the script as an argument for you.
this prevents you needing to mess about with executable names, by messing with the executable names you are breaking your own pip installation. in short there is no reason you should ever need to rename them.
I have the same error when I install python2.7 and python3.6 in my Window7.
After I rename my python.exe, there was an error using pip.
If your pip is the last version,you have to reinstall your pip use the command python3 -m pip install --upgrade --force-reinstall pip.
If your pip is not the last verison ,you can just upgrade your pip with the command python3 -m pip install --upgrade pip.
NOTE. When you install pip for your python2, you hava to change the command as python2 -m pip install --upgrade --force-reinstall pip.
Hope it works for you~

Pip.exe from Python on Windows 10

I installed the latest version of Python from www.python.org. Python 3.4.3. I then go to run pip and I get
"Fatal error in launcher: Job information querying failed"
Searching for this error message points me to similar issues running Python under wine. If you grab a pre-compiled pip.exe it will work but it seems that when you install, the pip.exe is generated as part of the installer and this pip.exe does not work.
Further I am dealing with a build script that creates a virtual python environment that uses pip.exe and results in the same error. Not sure how to fix this. Also not sure how pip.exe is generated.
You can use python -m pip install package
Worked for me in windows 10, make sure that you have added python in path of system environment variable. If you are able to run python from powershell then it means python is added to your path. After that you may try using following to upgrade pip
python -m pip install -U pip

Categories