24

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.

Bastien
  • 369
  • 1
  • 2
  • 5
  • Silly comment (on Windows so can't test much atm), but if you replace the Anaconda python executable with the pypy one, what happens? – Evan Nov 12 '18 at 17:33
  • 1
    Seems like `conda create -n pypy3 -c conda-forge pypy3.5` would work. You're trying to give a version for the `python` package, which conda doesn't know what to do with – darthbith Nov 12 '18 at 20:46
  • Thanks for the command @darthbith. It does create an environment with PyPy into it BUT it doesn't help here since I have to specify `pypy3` instead of Python and pip install packages but those are not seen by my PyPy. While I understand my question is ambiguous, I'm basically trying to get PyPy to be seen as a regular version of Python. I want to do this because PyPy should work with most pure Python packages. I'd like to be able to use it when I don't do anything fancy basically. I'll edit my question to make that clearer. – Bastien Nov 14 '18 at 14:13
  • @Bastien I think mattip's answer is what you want. Basically, support for pypy wasn't built in to conda, but it is now — and they're actively working on ironing out any remaining problems. – Mike Aug 23 '20 at 18:56

4 Answers4

19

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.

Mike
  • 19,114
  • 12
  • 59
  • 91
mattip
  • 2,360
  • 1
  • 13
  • 13
  • Note this also works on windows now. You need to create a **new conda environment**, you cannot install into an existing CPython one – mattip Sep 08 '21 at 16:18
8

Worked for me like this:

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

Afterwards you have to link to the pypy3 interpreter within the bin directory of the env

ln -s pypy3 python
trbck
  • 5,187
  • 6
  • 26
  • 29
4

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/

Hansang
  • 1,494
  • 16
  • 31
  • is pypy its own universe requiring its own separate installs? or does it share anything with the conda environment? – matanster Sep 18 '19 at 14:42
  • 1
    from my testing and what i've read, it's a completely separate install/interpreter 'runtime'. The documentation is still pretty lacking TBH – Hansang Sep 25 '19 at 02:24
0

I'm not sure what changed, but conda install pypy3 definitely doesn't work for me (Jan-2021):

conda install pypy3
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - pypy3

Current channels:

  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.
  • 1
    It worked for me using `conda-forge` and either installing only `pypy` (currently resulting in pypy3.7) or specifying a version number, e.g., `pypy3.7`. Complete command: `conda install -c conda-forge pypy` for latest version or `conda install -c conda-forge pypy3.6` for a specific version. – Valentin Kuhn Apr 02 '21 at 11:28