3
votes

I use Julia 1.6.0 (beta as of today) and would like to use a Python package plfit via PyCall.

Unfortunately, plfit is not available in Anaconda and hence I cannot install it using Conda module:

julia> using Conda

julia> Conda.add("plfit")
[ Info: Running `conda install -y plfit` in root environment
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:

  - plfit

...

How can I install this package from Julia?

2
Ser also the build script of the OdsIo.jl package.Antonello
Yes this is very useful. However as of today: (1) pip is included with PyCall so it seems no installation actions are required here. (2) If pip is missing I would definitely install pip via Conda.runconda(`install -c anaconda pip `). (3) I am using JULIA_DEPOT_PATH and find that having Python packages in --user environments is usually source of problems (Python's package management robustness is not any close to that of Julia). Again this is just my personal view on that :-)Przemyslaw Szufel

2 Answers

8
votes

You can run pip from Julia via the PyCall module.

Additionally, the package plfit has a reference to a cython package that is not present in Python in-built Julia and does not get installed automatically. Hence you need to do:

using PyCall
run(`$(PyCall.python) -m pip install --upgrade cython`)
run(`$(PyCall.python) -m pip install plfit`)

Now the plfit package will be available for use from Julia:

julia> plfit = pyimport("plfit");

julia> x=rand(1000);

julia> myplfit = plfit.plfit(x)
PYTHON plfit executed in 0.064029 seconds
xmin: 0.397582 n(>xmin): 625 alpha: 2.92546 +/- 0.0770183   Log-Likelihood: 36.3511   ks: 0.197384 p(ks): 4.09676e-22
PyObject <plfit.plfit.plfit object at 0x0000000064871A90>

Finally, note that sometimes some packages installed this way might have problems finding binary Python dependencies (not the case with plfit). In that case you need to add the folder %HOMEPATH%\.julia\conda\3\Library\bin to your PATH environment variable (replace %HOMEPATH%\.julia with JULIA_DEPOT_PATH or an appropriate system path depending on your configuration and platform).

0
votes

You can use pip also with Conda.jl (comes with PyCall):

https://github.com/JuliaPy/Conda.jl#conda-and-pip