How to create a Conda environment that uses PyPy?

大城市里の小女人 提交于 2021-02-18 05:05:35

问题


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.


回答1:


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.




回答2:


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/




回答3:


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



回答4:


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.


来源:https://stackoverflow.com/questions/53266913/how-to-create-a-conda-environment-that-uses-pypy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!