alexandrupaler / fondq

10 stars 1 forks source link

Can't install PyPI packages (cirq) for PyCall in Windows (Mac?) #2

Open madhavkrishnan opened 3 years ago

madhavkrishnan commented 3 years ago

This is related to how PyCall is installed in Windows / Mac as opposed to Linux.

From PyCall documentation :

By default on Mac and Windows systems, Pkg.add("PyCall") or Pkg.build("PyCall") will use the Conda.jl package to install a minimal Python distribution (via Miniconda) that is private to Julia (not in your PATH). You can use the Conda Julia package to install more Python packages, and import Conda to print the Conda.PYTHONDIR directory where python was installed. On GNU/Linux systems, PyCall will default to using the python3 program (if any, otherwise python) in your PATH. '

PyCall will by default use this julia only conda installation.

You can use Conda.jl to install packages using the methods described here. However the default installed version does not support installing PyPI packages with pip.

It is possible to get PyCall to use an existing Conda installation and point to a virtual env it will name conda_jl as described here. This env can be activated as usual with conda activate conda_jl from the terminal and packages can be installed directly. This workaround is less desirable than the following approach

The latest version experimental version of Conda.jl has support for PyPI packages and can be installed from julia by running,

Pkg.add(PackageSpec(name="Conda", rev="master")

You might need to run Pkg.build("Conda") if Conda is not build automatically. Now, you can run the following code to install a PyPI only package such as cirq,

using Conda
Conda.pip_interop(true)
Conda.pip("install", "cirq")