Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Conda environment that uses PyPy?

Tags:

So here is my issue. I've managed to install PyPy using conda with the following command:

conda install -c conda-forge pypy3.5

Unfortunately, when I try to create an environment that uses this pypy3 exectuable, I cannot find a way to do it. If I run pypy3, I get the PyPy shell without any issue and I can also run my programs using pypy3 instead of python.

Though now, I'd like to be able to create a full environment using PyPy if that's possible. I've tried things like the following in vain:

conda create -n pypy3 python=pypy3
conda create -n pypy3 python=pypy3 -c conda-forge

I've tried specifying pypy3.5, and other variations but nothing works. I can see the pypy3 executable in the bins of my Miniconda installation but I cannot find a way for Conda to use it. I cannot find much on the internet on this since people seem to be asking just for the install of PyPy via Conda, and nothing about creating environments using PyPy.

So here are my questions:

  • Is there already a way to create a Conda environment using PyPy instead of a regular CPython?
  • Is there a way to force Conda to look first locally instead of checking online for distributions?
  • Is there a way to enforce an executable to use as Python when we create an environment with Conda?
  • Would there be a dirty workaround possible creating a regular environment and then forcing this environment to point to my pypy3 executable?

I don't know if anybody can help here. Maybe the solution already exists but I couldn't find much on the subject anyway.

EDIT: As suggested by @darthbith I can use the following command:

conda create -n pypy3 -c conda-forge pypy3.5

But that doesn't do what I would expect. I can use pypy3 to get the shell and execute my Python programs but it is not handled as a regular Python version. I'd like to have PyPy to be considered like any version of Python and be able to use pip to install packages (most pure Python packages should work with PyPy).

I understand that a lot of people would advise against what I'm trying to do here, but I see it as just being a faster version of Python that works for anything that doesn't rely on C libraries. Since I'm working on pure Python libraries and many libraries in PyPi are written in pure Python, I don't see why I wouldn't be able to achieve what I'm trying to do here.

like image 491
Bastien Avatar asked Nov 12 '18 17:11

Bastien


People also ask

How do you use PyPy in Python?

For Python 2.7, it's just called pypy . For CPython, if you would like to run Python 3 from the terminal, you simply enter the command python3 . To run PyPy, simply issue the command pypy3 . Entering the pypy3 command in the terminal might return the Command 'pypy3' not found message, as shown in the next figure.

Can I use pip in conda ENV?

You can install pip in the current conda environment with the command conda install pip , as discussed in Using pip in an environment. If there are instances of pip installed both inside and outside the current conda environment, the instance of pip installed inside the current conda environment is used.


2 Answers

Conda now supports PyPy more smoothly.

conda config --set channel_priority strict
conda create -c conda-forge -n pypy pypy
conda activate pypy

There's still a lot of work being done to build conda packages for pypy, but there's already a lot of compatibility. For example,

conda install mpmath
conda install numpy

both work now.

Reference: https://conda-forge.org/blog/posts/2020-03-10-pypy

Also note that the official recommendation for using pip with pypy is described here, the key point of which is this:

Best practices with pip is to always call it as <python> -mpip ..., but if you wish to be able to call pip directly from the command line, you must call pypy -mensurepip --default-pip.

like image 152
mattip Avatar answered Sep 22 '22 23:09

mattip


Might not achieve exactly what you want, but here's what i've done:

Make a new conda env

conda create --name pypy_env
conda activate pypy_env

Install pypy3 using conda

conda install pypy3

Get Pip for pypy3 using the method here Install pip on pypy

Install packages for pypy using

pypy3 -m pip install <name_of_package>

For some packages it's eaiser to use the pre-built pypy wheel files, some you can find here https://www.lfd.uci.edu/~gohlke/pythonlibs/

like image 40
Spcogg the second Avatar answered Sep 23 '22 23:09

Spcogg the second