40

I want to speed up my program so i'm trying to setup pypy + psycopg2cffi. This program opens a xml, parses it and then insert some data in a database. I'm using currently python3, postgresql and psycopg2 but this approaches is really slow. So i want to try run my program with pypy + psycopg2cffi. I have python 3 and pypy, and i want to install psycopg2cffi so i ran this command:

pip install psycopg2cffi psycopg2cffi-compat 

But psycopg2cffi was only installed on python because when i try to import psycopg2cffi on pypy this is the error i get:

ImportError: No module named psycopg2cffi

So i think i need to install pip first but i can figure out how to do this.

How can i install it on pypy? Thank you.

9
  • See doc.pypy.org/en/latest/install.html#installing-more-modules . Note also that the officially released PyPy-for-3.x is old and slow; better wait for the next one (or use PyPy-for-2.7).
    – Armin Rigo
    Commented Feb 20, 2017 at 14:11
  • when i try to run ./usr/bin/pypy -m ensurepip i get this error ensurepip is disabled in Debian/Ubuntu for the system python. Python modules For the system python are usually handled by dpkg and apt-get. apt-get install pypy-<module name> Install the python-pip package to use pip itself. Using pip together with the system python might have unexpected results for any system installed module, so use it on your own risk, or make sure to only use it in virtual environments. @ArminRigo
    – 1pa
    Commented Feb 20, 2017 at 15:58
  • 1
    IMO, the only sensible way of using pypy3 on Debian/Ubuntu is to create a virtualenv for it, using something like virtualenv -p pypy3 pypy3-env. (Note that an up-to-date virtualenv running on CPython2 is perfectly capable of creating pypy3 environments.)
    – Ronan Lamy
    Commented Feb 20, 2017 at 18:21
  • thank you!! @RonanLamy Now i have pip: /usr/local/bin/pip /usr/local/bin/pip2.7 /home/p/Desktop/pypy-env/bin/pip /home/p/Desktop/pypy-env/bin/pip2.7 /home/anaconda3/bin/pip and even with pip i can't install psycopg2cffi on pypy why?
    – 1pa
    Commented Feb 20, 2017 at 20:04
  • @1pati2 Did you activate the virtualenv? What error are you getting?
    – Ronan Lamy
    Commented Feb 20, 2017 at 20:28

5 Answers 5

75

You can also try this (if it's not disabled in your Linux distribution):

pypy -m ensurepip
3
  • 8
    Works great, this saves the trouble of downloading get-pip.py. Also works on Windows.
    – gaborous
    Commented Aug 5, 2017 at 2:46
  • 4
    Why is this disabled on some linux distros, and how can it be enabled? Commented Oct 10, 2019 at 22:35
  • 11
    ensurepip is disabled in Debian/Ubuntu for the system python.
    – Pygmalion
    Commented Dec 4, 2019 at 16:14
50

Download the pip-installer and execute it with pypy:

wget https://bootstrap.pypa.io/get-pip.py
./pypy get-pip.py

For usage try,

pypy -m pip install validators
2
  • On my win10 (1809) and PyPy 7.3.1, get-pip.py crashed on compilation.
    – Fred Qian
    Commented Apr 16, 2020 at 3:09
  • ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.7. Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead.
    – Galen
    Commented Oct 15, 2023 at 2:15
4

For me, "pypy -m ensurepip" didn't work with a pypy3 installed with apt-get under Kubuntu 20.04. Probably disabled in the repository, as comments point in @SebMa answer. I was trying to run sympy with pypy3, so I needed pip working with pypy3. I managed to get it working with pypy3 installed with Anaconda:

conda config --set channel_priority strict
conda create -n pypy3 -c conda-forge pypy3.6
conda activate pypy3
pypy3 -m ensurepip
pypy3 -m pip install sympy

This question and its answers were also helpful: How to create a Conda environment that uses PyPy?

3

I installed pip via

wget https://bootstrap.pypa.io/get-pip.py
pypy3 get-pip.py

then

pypy3 -m pip install "module"

solved my issue. @kleite thanx

0

I'm using pip with pypy3 on Ubuntu 22.04. Installing the "python3-pip" package or manipulating packages in a "pypy3-venv" seems to solve the problem. I prefer "pypy3-venv".

Start

# apt update && \
  apt install software-properties-common && \
  add-apt-repository ppa:pypy/ppa && \
  apt install pypy3

# pypy3 --version
Python 3.9.19 (7.3.16+dfsg-2~ppa1~ubuntu22.04, Apr 26 2024, 13:22:45)
[PyPy 7.3.16 with GCC 11.4.0]

# python3 --version
Python 3.10.12

# pypy3 -m pip
/usr/bin/pypy3: No module named pip
  (to install pip, you need to run once "/usr/bin/pypy3 -m ensurepip")

"python3" is a dependency of "software-properties-common".

The python3-pip way

I thought the "pypy3-pip" package existed, but:

# apt install pypy3-pip
E: Unable to locate package pypy3-pip

So I tried "python3-pip":

# apt install python3-pip

# pypy3 -m pip --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)

# python3 -m pip --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10) 

Is the /usr/lib/python3/dist-packages/* directory shared with python3 and pypy3? I don't know.

Install packages and their dependencies:

# apt install libpq-dev pypy3-dev && \
  pypy3 -m pip install psycopg2cffi psycopg2cffi-compat && \
  pypy3 -m pip list
...
WARNING: Running pip as the 'root' user can result in broken permissions
  and conflicting behaviour with the system package manager. It is
  recommended to use a virtual environment instead:
  https://pip.pypa.io/warnings/venv
...
Package             Version
------------------- -----------
...
psycopg2cffi        2.9.0
psycopg2cffi-compat 1.1
...

Then import "psycopg2cffi":

# pypy3 -c 'import psycopg2cffi'; echo $?
0

The pypy3-venv way

We can also deploy a "venv":

# apt install pypy3-venv && \
  pypy3 -m venv .venv && \
  source .venv/bin/activate

(.venv)
# which pypy3 python3 pip3 && pip3 --version
/.venv/bin/pypy3
/.venv/bin/python3
/.venv/bin/pip3
pip 22.0.2 from /.venv/lib/pypy3.9/site-packages/pip (python 3.9)

(.venv)
# apt install libpq-dev pypy3-dev && \
  pip3 install psycopg2cffi psycopg2cffi-compat && \
  pip3 list
...

(.venv)
# pypy3 -c 'import psycopg2cffi'; echo $?
0

# deactivate

# pypy3 -c 'import psycopg2cffi'; echo $?
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'psycopg2cffi'
1

Please note the package "python3-setuptools-whl":

# apt-cache depends pypy3-venv
pypy3-venv
  Depends: pypy3
  Depends: python3-pip-whl
  Depends: python3-setuptools-whl

# dpkg -L python3-pip-whl
...
/usr/share/python-wheels/pip-22.0.2-py3-none-any.whl

.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.