This article is WIP
im not done writing or improving this. Expect typos, weird grammar and general badness.
Im going to outline a few common issues with pip, python versions and python packages. Im not going to recommend any specific tool, but rather show a good way of managing things yourself.
- Why not conda?
- Help, i cant import the package i just installed!
- How do i run my python scripts with the version i want?
- How do i properly install python?
To check the Python version, use
To check if you're running 32 or 64 but python, use
python -V -V. It should tell you the exact version, including something like
64 bit (AMD64).
To check the pip version, use
This should tell you something like
pip 20.2.3 from c:\python39\lib\site-packages\pip (python 3.9). The important part here is the last bit,
python 3.9. Make sure this matches your python version.
Heres some resources on how to check in different IDEs or Editors:
So, you're trying to import a package but it just wont work. You just get a
Lets start with the obvious question: Did you actually install the package? Normally, packages are installed with
pip install packagename.
Another reason this may fail is a mismatch in the version. Follow the steps in the How to check what version im using section and make sure the python version of pip matches the python version you're using, whether you're using commandline to run your code or a IDE. If you want to make sure you're installing the packages in the correct python version, use
python -m pip install packagename, this makes sure pip is using the same version that the
python command is referring to.
There are also some packages that are installed under a different name than the one used for importing. For example, discord.py, a popular Python framework for making discord bots, is installed with
pip install discord.py, but imported as
import discord. In a similar vein, packages that have a
- in the name are often imported with a
_ instead of a
How do i run my python scripts with the version i want?
There are multiple ways you can specify the version, some are dependent on your Operating System (Windows, Linux)
On Windows: By default, python installations on Windows come with whats called the "pyLauncher", which makes it easy to run any of the installed versions.
The pylauncher is used with
py which should refer to the same version as the
python command by default. Other versions can be accessed by passing the version like this
a few examples:
py my_file.pyruns the python file with the primary python version
py -3.8 my_file.pyruns python with the specified version (3.8)
py -3.8 -m pip install requestsruns pip for the specified version (3.8) and installs the requests package
py --listlists all avaliable versions
On Linux: When installing multiple python versions in most linux distros, their binaries are automatically on the PATH as
python3.9 etc. This makes it easy to install and use multiple versions. In many distributions,
python refers to Python 2, whereas
python3 refers to the primary version of Python 3
a few examples:
python3 my_file.pyruns the python file with the primary python version
python3.8 my_file.pyruns python with the specified version (3.8)
python3.8 -m pip install requestsruns pip for the specified version (3.8) and installs the requests package
ls -ls /usr/bin/python*lists all avaliable versions