I have searched everywhere. There is no answer for my specific problem! I have Ubuntu, I want to use pygame on Python 3. I installed the pygame package with
sudo apt-get python-pygame
but it just doesn't work when I type
import pygame
Please help!
You must install pip for python3
$ sudo apt install python3-pip
and then, with the pip installed, install pygame
$ pip3 install pygame
Ubuntu 19.04 and later
To install python3-pygame in Ubuntu 19.04 and later open the terminal and type:
sudo apt install python3-pygame
Ubuntu 18.10
To install python3-pygame in Ubuntu 18.10 open the terminal and type:
sudo nano /etc/apt/sources.list
Add this line to sources.list.
deb http://archive.ubuntu.com/ubuntu/ cosmic-proposed universe
Save sources.list with the keyboard combination Ctrl+O and press Enter and exit with Ctrl+X
Update the list of available software and install python3-pygame.
sudo apt update
sudo apt install python3-pygame
Ubuntu 16.04-18.04
sudo apt install python3-setuptools
sudo easy_install3 pip
python3 -m pip install --user pygame
The pygame package on Ubuntu is only for python 2.7, so it is impossible to import if you use python 3. If you want python 3.x support, you need to install pygame 1.9.2 which is located at https://bitbucket.org/pygame/pygame/downloads
If you have all the dependencies installed, it should be as simple as running setup.py
I'm at a Pop-OS 20.04 machine and all of those answers didn't work for me (◉_◉). So I went to the documentation of Pygame and realized that I had to have the dependencies installed. To do that you can:
sudo apt-get install git python3-dev python3-setuptools python3-numpy python3-opengl \
libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev \
libtiff5-dev libx11-6 libx11-dev fluid-soundfont-gm timgm6mb-soundfont \
xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic fontconfig fonts-freefont-ttf libfreetype6-dev
Now you are ready to install Pygame, so git clone their GitHub repository into your current folder and pip install the module:
git clone https://github.com/pygame/pygame.git
If you are using Python 2 go to this URL: https://www.pygame.org/wiki/CompileUbuntu?parent=
Related
I'm using instructions that I found on PyImageSearch (here) to install Open CV on a brand new Raspberry Pi3 Buster O/S, but I'm running into problems finding a version of opencv-contrib-python that satisfies the version requirements. Here is a list of all commands issued.
sudo apt-get update
sudo apt-get dist-upgrade
python3 -m venv .opencv
source .opencv/bin/activate
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo pip install opencv-contrib-python==4.1.0.25
Upon issuing the last command, I get the failure "could not find a version that satisfies the requirement..." I have tried using the latest version 4.5.2.54 with the same result. The latest version of Buster comes with Python 3.7.3.
I suspect the PyImageSearch site is just out of date. Is this just a matter of finding the correct version, or am I just doing this the wrong way?
I found a user's post on the PyImageSearch web site. The solution is to install the latest version of pip as follows.
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
I'm trying to install pip for Python 3.8 on an Ubuntu 18.04 LTS.
I know this has been asked way too many times. But those questions do not concern keeping Ubuntu's defaults specifically. And the answers on those questions either don't work or go on to suggest something so drastic that it would break the system - e.g. change default python3 version from 3.6 to 3.8. You SHOULDN'T!
So far, I've been able to install python3.8 successfully using the PPA - ppa:deadsnakes/ppa:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8
Changed python command from python2 to python3.8 using update-alternatives:
update-alternatives --remove python /usr/bin/python2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10
Now, I get python 3.8 when I run python --version:
Python 3.8.5
The problem is, I still can't install pip for Python 3.8.
If I try to install python3-pip, it installs pip for Python 3.6 since python3 still points to python3.6.9, and I intend to keep it that way.
Try installing python-pip, and it will install pip for Python 2.7.
Also there's no such package as python3.8-pip, so I can't install it like:
sudo apt install python3.8-pip
Output:
E: Unable to locate package python3.8-pip
E: Couldn't find any package by glob 'python3.8-pip'
E: Couldn't find any package by regex 'python3.8-pip'
What can I do to install pip for Python 3.8 on an Ubuntu 18.04?
While we can use pip directly as a Python module (the recommended way):
python -m pip --version
This is how I installed it (so it can be called directly):
Firstly, make sure that command pip is available and it isn't being used by pip for Python 2.7
sudo apt remove python-pip
Now if you write pip in the Terminal, you'll get that nothing is installed there:
pip --version
Output:
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
Install python3.8 and setup up correct version on python command using update-alternatives (as done in the question).
Make sure, you have python3-pip installed:
(This won't work without python3-pip. Although this will install pip 9.0.1 from python 3.6, we'll need it.)
sudo apt install python3-pip
This will install pip 9.0.1 as pip3:
pip3 --version
Output:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
Now, to install pip for Python 3.8, I used pip by calling it as a python module (ironic!):
python -m pip install pip
Output:
Collecting pip
Downloading https://files.pythonhosted.org/packages/36/74/38c2410d688ac7b48afa07d413674afc1f903c1c1f854de51dc8eb2367a5/pip-20.2-py2.py3-none-any.whl (1.5MB)
100% |████████████████████████████████| 1.5MB 288kB/s
Installing collected packages: pip
Successfully installed pip-20.2
It looks like, when I called pip (which was installed for Python 3.6, BTW) as a module of Python 3.8, and installed pip, it actually worked.
Now, make sure your ~/.local/bin directory is set in PATH environment variable:
Open ~/.bashrc using your favourite editor (if you're using zsh, replace .bashrc with .zshrc)
nano ~/.bashrc
And paste the following at the end of the file
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
Finally, source your .bashrc (or restart the Terminal window):
source ~/.bashrc
Now if you try running pip directly it'll give you the correct version:
pip --version
Output:
pip 20.2 from /home/qumber/.local/lib/python3.8/site-packages/pip (python 3.8)
Sweet!
As suggested in official documentation you can try with get-pip.py.
wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py
This will install pip as pip3.8
Another solution would be to install the pip that is in apt. sudo apt install python3-pip. The version of the pip that it installs is for all versions of Python not only for version 3.6 once installed you just need to update the pip with the command python3.8 -m pip install pip and he will be install the latest version of pip for Python.
I would not advise you to remove Python2 because it is an important module for the system you should just create a permanent "alias" in .bashrc for Python3 I did like this alias python="python3.8.
# install py3.8 and dependencies for the pip3 bootstrap script
add-apt-repository -y ppa:deadsnakes/ppa && \
apt install -y python3.8 python3.8-distutils
# download and run the pip3 bootstrap script
cd /tmp && wget https://bootstrap.pypa.io/get-pip.py && \
python3.8 /tmp/get-pip.py
# use pip py3.8 module to install python packages
python3.8 -m pip install numpy pandas
Install python v3.8 as python
RUN apt update --fix-missing && \
apt install python3.8 -y && \
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 10
Install pip for python 3.8
RUN apt install python3-pip -y && \
python -m pip install --upgrade pip
I did this a couple days ago and I struggled a lot with it but I finally got it working, so I wrote up what I did as a blog post.
In the end I think I may have done mostly the same things as the above answer, but if you got lost following it, maybe my screenshots etc will help.
Here's the tl;dr of the process I did:
Uninstall python3-pip & python-pip using apt
Remove the old pip files from /usr/local/bin
Reinstall python3-pip using apt
Add $HOME/.local/bin to your $PATH (also restart your shell to make sure you did this right)
On ubuntu server
sudo apt install python -y
For more information check this blog here.
https://teckresolve.com/install-python-packages-using-pip/
OK so I am a total noob and I just installed Kali Linux. I am trying to install python-pip by command
apt-get install python-pip
and I am getting this output
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-pip
I've checked my source /ect/apt/sources.list and it says
deb http://http.kali.org/kali kali-last-snapshot main non-free contrib
I've run apt-get updates several times too and it's not helping. Please help.
At-First Open Your sources.list File With any Editor.
nano /etc/apt/sources.list
and add these Lines.
deb http://http.kali.org/kali kali-rolling main non-free contrib
deb-src http://http.kali.org/kali kali-rolling main non-free contrib
Not Update and Upgrade Your Kali Linux Using These Commands.
apt-get update
apt-get upgrade
and then Install pip using this command
apt-get install python-pip #For Python2
apt-get install python3-pip #For Python3
There is a high chance python-pip is not available, because 'python' is python2, and python2 is finally dead. Try to install python3-pip.
There is a convention that python without '3' is python2, and it's gonna last like that, I think, forever, due to compatibility reasons.
cd /
cd etc/apt/
sudo nano sources.list
After opening the editor paste the following line if not present.
deb http://http.debian.net/debian jessie-backports main
deb http://http.kali.org/kali kali-rolling main contrib non-free
run the following command
sudo apt upgrade
sudo apt install python-pip
This should work for you.
Try running apt-get install python3-pip. This will install pip3 on your machine.
I tried with sudo apt install python3-pip and didn't work. So I tried again with sudo apt-get install python3-pip and it worked fine. I'm using Kali Linux too.
You need to add the repositories to sources.list
nano /etc/apt/sources.list
And add
deb http://http.kali.org/kali kali-rolling main non-free contrib
deb-src http://http.kali.org/kali kali-rolling main non-free contrib
Save and run
apt-get update
apt-get upgrade
apt-get install python-pip #or python3-pip
And type
pip --version #or pip3
To more info click here and here
Use this to install pip for python 2.7:
curl https://bootstrap.pypa.io/2.7/get-pip.py -o get-pip.py
python get-pip.py
Now you have:
$ pip --version
pip 20.3.4 from /home/kali/.local/lib/python2.7/site-packages/pip (python 2.7)
$ pip3 --version
pip 21.0.1 from /home/kali/.local/lib/python3.9/site-packages/pip (python 3.9)
apt-get update
apt-get upgrade
This works
sudo apt update
sudo apt install python3
sudo apt install python3-pip
python3 -m pip install -r
This video helped me: https://www.youtube.com/watch?v=9EHUGDnvqoA
Try following commands:
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install python-pip
Hope it will help u!
Make your source.list like this
nano /etc/apt/source.list
deb http://http.kali.org/kali kali-last-snapshot main non-free contrib
deb http://http.kali.org/kali kali-rolling main non-free contrib deb-src
http://http.kali.org/kali kali-rolling main non-free contrib
Update Your kali
sudo apt-get update && upgrade
Now install python-pip
apt-get install python-pip or apt-get install python3-pip
It works for me:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py && python get-pip.py
If already python 2.7 version is installed , first remove that in cmd terminal
Type >> sudo apt purge -y python2-minimal
then install python latest version
Type >> sudo apt install -y python3-pip
python is installed!
Not found pip try this command
1: sudo apt install python3-pip
2: pip3 install -r requirements.txt
3: /usr/local/bin/python3.10 -m pip install --upgrade pip
i have same issue that i was using python2 not python3 you may check your python version you have
Try this :
sudo apt update
sudo apt install python3
sudo apt install python3-pip
python3 -m pip install -r
I had the same issue, here is the command that helped me:
sudo apt install python-pip
This command will install pip to your system.
CentOS 7 already has Python2.7.5 stock installed. I am doing an online course that requires Python3.x installed. So these are the following steps i took to install Python3.7.3.rc1 :
$cd /usr/src
$sudo wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3rc1.tgz
$sudo tar xzf Python-3.7.3rc1.tgz
$cd Python-3.7.3rc1
$sudo ./configure --enable-optimizations
$sudo make altinstall
$sudo rm /usr/src/Python-3.7.3rc1.tgz
$python3.7 --version
Python 3.7.3rc1
I followed these steps religiously from this link : https://tecadmin.net/install-python-3-7-on-centos/
During my course i was required to install pyperclip using pip.
So i did :
$python3.7 -m pip install pyperclip
/usr/local/bin/python3.7: No module named pip
Please suggest a method to install pip for Python3.7.3rc1.
You should have taken the default available python3, that is the python3.6 package in centos7
that would have been easier to setup rather than compile an unsupported version.
Suggest you install the supported python3 package in centos
Try doing yum install python36 from repository
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
Update yum package
sudo yum update
Install python36 along with pip
sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
Below steps are for python3.7,
suggest avoiding unsupported packages.
Alternate Steps for pip setup for Centos
You need to install pip for python3.7 series
Step 1: First install the EPEL Repository
sudo yum install epel-release
Step 2: Installing pip
python37 -m pip
Step 3: Verify if pip was installed properly
pip --version
If the command not found error shows up, try
python37 -m ensurepip
I also as you said "followed these steps religiously from this link: https://tecadmin.net/install-python-3-7-on-centos/."
It was not an option for me to install python3.6, as I explicitly needed 3.7.
I was able to install using the following procedure:
# AFAIK, libffi-devel solved the "ModuleNotFoundError: No module named '_ctypes'" I had when I tried installing without it.
yum install libffi-devel
cd /usr/src
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar xzf Python-3.7.5.tgz
cd Python-3.7.5
./configure --enable-optimizations
make install # Or: make altinstall
python3 -V
pip3 --version
rm -f /usr/src/Python-3.7.5.tgz
What I changed from the referenced article is the version (3.7.5 instead of 3.7.4) and in addition installed "libffi-devel". It could be that this one would have solved on 3.7.4 as well.
For CentOS 6 and 7 you can run this:
sudo yum install python37-setuptools
sudo easy_install-3.7 pip
Edit: You should then be able to install using pip3 install <package>
I've installed Python 3.7 on my Ubuntu 18.04 machine. Following this instructions in case it's relevant:
Download : Python 3.7 from Python Website [1] ,on Desktop and manually
unzip it, on Desktop Installation : Open Terminal (ctrl +shift+T)
Go to the Extracted folder
$ cd ~/Desktop/Python-3.7.0
$ ./configure
$ make
$ sudo make install
Making Python 3.7 default Python :
$ sudo vim ~/.bashrc
press i
on the last and new line - Type
alias python= python3.7
press Esc
type - to save and exit vim
:wq
now type
$ source ~/.bashrc
From here: https://www.quora.com/How-can-I-upgrade-Python-3-6-to-3-7-in-Ubuntu-18-04
I've downloaded several modules through pip install module but when I try to import them, I get a ModuleNotFoundError: No module names 'xx'
So I did some research and apparently when used pip to install, it installed in the modules in previous version of Python.
Somewhere (probably a question in SO) I found a suggestion to install the module using python3.7 -m pip install module but then I get /usr/local/bin/python3.7: no module named pip.
Now I'm stuck, pip is installed, but apparently not for Python 3.7. I'm assuming that if I can install pip for Python 3.7, I can run the pip install command and get the modules I need.
If that is the case, how can I install pip for python 3.7, since it's already installed?
This is the best I have come up with:
I have installed python 3.7 successfully and I can install modules using pip (or pip3) but those modules are installed in Python 3.6 (Comes with ubuntu). Therefore I can't import those modules in python 3.7 (get a module not found)
Python 3.7 doesn't recognize pip/pip3, so I can't install through pip/pip3
I need python 3.7
In general, don't do this:
pip install package
because, as you have correctly noticed, it's not clear what Python version you're installing package for.
Instead, if you want to install package for Python 3.7, do this:
python3.7 -m pip install package
Replace package with the name of whatever you're trying to install.
Took me a surprisingly long time to figure it out, too. The docs about it are here.
Your other option is to set up a virtual environment. Once your virtual environment is active, executable names like python and pip will point to the correct ones.
A quick add-on to mpenkov's answer above (didn't want this to get lost in the comments)
For me, I had to install pip for 3.6 first
sudo apt install python3-pip
now you can install python 3.7
sudo apt install python3.7
and then I could install pip for 3.7
python3.7 -m pip install pip
and as a bonus, to install other modules just preface with
python3.7 -m pip install <module>
EDIT 1 (12/2019):
I know this is obvious for most. but if you want python 3.8, just substitute python3.8 in place of python3.7
EDIT 2 (5/2020):
For those that are able to upgrade, Python 3.8 is available out-of-the-box for Ubuntu 20.04 which was released a few weeks ago.
This works for me.
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then this command with sudo:
python3.7 get-pip.py
Based on this instruction.
I used apt-get to install python3.7 in ubuntu18.04. The installations are as follows.
install python3.7
sudo apt-get install python3.7
install pip3. It should be noted that this may install pip3 for python3.6.
sudo apt-get install python3-pip
change the default of python3 for python3.7. This is where the magic is, which will make the pip3 refer to python3.7.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
Hope it works for you.
To install all currently supported python versions (python 3.6 is already pre-installed) including pip for Ubuntu 18.04 do the following:
To install python3.5 and python3.7, use the deadsnakes ppa:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5
sudo apt-get install python3.7
Install python2.7 via distribution packages:
sudo apt install python-minimal # on Ubuntu 18.04 python-minimal maps to python2.7
To install pip use:
sudo apt install python-pip # on Ubuntu 18.04 this refers to pip for python2.7
sudo apt install python3-pip # on Ubuntu 18.04 this refers to pip for python3.6
python3.5 -m pip install pip # this will install pip only for the current user
python3.7 -m pip install pip
I used it for setting up a CI-chain for a python project with tox and Jenkins.
Combining the answers from #mpenkon and #dangel, this is what worked for me:
sudo apt install python3-pip
python3.7 -m pip install pip
Step #1 is required (assuming you don't already have pip for python3) for step #2 to work. It uses pip for Python3.6 to install pip for Python 3.7 apparently.
When i use apt install python3-pip, i get a lot of packages need install, but i donot need them. So, i DO like this:
apt update
apt-get install python3-setuptools
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
rm -f get-pip.py
The following steps can be used:
sudo apt-get -y update
---------
sudo apt-get install python3.7
--------------
python3.7
-------------
curl -O https://bootstrap.pypa.io/get-pip.py
-----------------
sudo apt install python3-pip
-----------------
sudo apt install python3.7-venv
-----------------
python3.7 -m venv /home/ubuntu/app
-------------
cd app
----------------
source bin/activate
Install python pre-requisites
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Install python 3.7 (from ppa repository)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7
Install pip3.7
sudo apt install python3-pip
python3.7 -m pip install pip
Create python and pip alternatives
sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3.7 10
sudo update-alternatives --install /usr/local/bin/pip pip /home/your_username/.local/bin/pip3.7 10
Make changes
source ~/.bashrc
python --version
pip --version
For those who intend to use venv:
If you don't already have pip for Python 3:
sudo apt install python3-pip
Install venv package:
sudo apt install python3.7-venv
Create virtual environment (which will be bootstrapped with pip by default):
python3.7 -m venv /path/to/new/virtual/environment
To activate the virtual environment, source the appropriate script for the current shell, from the bin directory of the virtual environment. The appropriate scripts for the different shells are:
bash/zsh – activate
fish – activate.fish
csh/tcsh – activate.csh
For example, if using bash:
source /path/to/new/virtual/environment/bin/activate
Optionally, to update pip for the virtual environment (while it is activated):
pip install --upgrade pip
When you want to deactivate the virtual environment:
deactivate
I installed pip3 using
python3.7 -m pip install pip
But upon using pip3 to install other dependencies, it was using python3.6.
You can check the by typing pip3 --version
Hence, I used pip3 like this (stated in one of the above answers):
python3.7 -m pip install <module>
or use it like this:
python3.7 -m pip install -r requirements.txt
I made a bash alias for later use in ~/.bashrc file as alias pip3='python3.7 -m pip'. If you use alias, don't forget to source ~/.bashrc after making the changes and saving it.
How about simply
add-apt-repository ppa:deadsnakes/ppa
apt-get update
apt-get install python3.7-dev
alias pip3.7="python3.7 -m pip"
Now you have the command
pip3.7
separately from pip3.
curl https://bootstrap.pypa.io/get-pip.py | sudo python3.7
if all else fails.
pip3 not pip. You can create an alias like you did with python3 if you like.