Install pip on pypy
Asked Answered
H

5

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.

Hochheimer answered 20/2, 2017 at 10:27 Comment(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).Boydboyden
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. @ArminRigoHochheimer
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.)Claireclairobscure
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?Hochheimer
@1pati2 Did you activate the virtualenv? What error are you getting?Claireclairobscure
@RonanLamy yes i wrote source activate pypy-env `Hochheimer
@RonanLamy then pip install psycopg2cffi psycopg2cffi-compat and i'm getting this error: `Command "/home/p/Desktop/pypy-env/bin/pypy -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ron22/psycopg2cffi/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n','\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-cGNmfN-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/p/Desktop/pypy-env/include/site/python2.7/psycopg2cffi" failed with error code 1 in /tmp/pip-build-ron22h/psycopg2cffi/Hochheimer
@1pati2 Update pip (pip install -U pip) and see if it helps (e.g. by getting a less cryptic error)? If not, you should probably ask the psycopg2cffi maintainers.Claireclairobscure
Does pip_pypy work? Depending on how it was installed, PyPy comes with its own pip, which can be run with pip_pypy.Pascale
E
75

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

pypy -m ensurepip
Ess answered 24/6, 2017 at 14:55 Comment(3)
Works great, this saves the trouble of downloading get-pip.py. Also works on Windows.Lore
Why is this disabled on some linux distros, and how can it be enabled?Ammonium
ensurepip is disabled in Debian/Ubuntu for the system python.Haematoma
F
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
Foley answered 6/5, 2017 at 22:40 Comment(2)
On my win10 (1809) and PyPy 7.3.1, get-pip.py crashed on compilation.Reiser
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.Diestock
E
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?

Egin answered 5/1, 2021 at 15:47 Comment(0)
T
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

Teel answered 12/3, 2021 at 21:43 Comment(0)
L
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

.

Lamarckian answered 5/5 at 2:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.