# How to use Python library in Julia?

**URL:** https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644
**Category:** Machine Learning
**Tags:** question, pycall, pythoncall
**Created:** [February 2, 2022, 11:08am UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644 "2022-02-02T11:08:35Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 2, 2022, 11:08am UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/1 "2022-02-02T11:08:36Z")

</div>

I was wondering how can I use this package [https://github.com/DeepGraphLearning/ConfGF](https://github.com/DeepGraphLearning/ConfGF) in Julia by using PyCall.jl or PythonCall.jl?

this is how to use this package in python. I want to do it in Julia, is it feasible?

```nohighlight
# Create conda environment
conda create -n confgf python=3.7

# Activate the environment
conda activate confgf

# Install packages
conda install -y -c pytorch pytorch=1.7.0 torchvision torchaudio cudatoolkit=10.2
conda install -y -c rdkit rdkit==2020.03.2.0
conda install -y scikit-learn pandas decorator ipython networkx tqdm matplotlib
conda install -y -c conda-forge easydict
pip install pyyaml

# Install PyTorch Geometric
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-geometric==1.6.3

# Install Library
git clone https://github.com/DeepGraphLearning/ConfGF.git
cd ConfGF
python setup.py install

```

it also needs command line to train the model.

Thank you in advance

---

<div class="post-metadata">

### Author: ![sashmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sashmit/32/18791_2.png) [@sashmit](https://discourse.julialang.org/u/sashmit)
#### Post date: [February 2, 2022, 1:02pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/2 "2022-02-02T13:02:33Z")

</div>

Because of the heavy amount of dependencies, it sounds like pythoncall would be your best bet.

---

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 2, 2022, 4:41pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/3 "2022-02-02T16:41:08Z")

</div>

Thank you, from the tutorial of PythonCall.jl, it seems there is no material for this kind of application, It would be helpful if anyone can share some successful experience?

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [February 2, 2022, 6:40pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/4 "2022-02-02T18:40:44Z")

</div>

It depends what you’re trying to achieve, but if you already have all that stuff installed into a Conda environment then you can do

```julia
ENV["JULIA_PYTHONCALL_EXE"] = "python"
using PythonCall
@py import confgf
...

```

That first line forces PythonCall to use Python from your own Conda environment.

---

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 2, 2022, 7:49pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/5 "2022-02-02T19:49:28Z")

</div>

No I have not install all the things, I was thinking there is conda in Julia package, can I install all the things with that conda? and use this library entirely in Julia. I want to train the model with my data in Julia and produce some results in Julia, in other words, I want to use this library without leaving Julia. Thank you very much for your help!

```nohighlight
python -u script/train.py --config_path ./config/qm9_default.yml
python -u script/train.py --config_path ./config/drugs_default.yml
python -u script/train.py --config_path ./config/iso17_default.yml

```

It also needs command line to train the model like that

If I install all these in a python environment, it need to create a virtual environment (“confgf”)

So we just import this library from this virtual environment in Julia with PythonCall?

How about the command line trainning part?

---

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 5, 2022, 11:56am UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/6 "2022-02-05T11:56:23Z")

</div>

I installed the packages , and did as following:

```julia
ENV["JULIA_PYTHONCAL_EXE"] = "/usr/local/Caskroom/miniconda/base/envs/confgf/bin/python"
using PythonCall
@py import confgf

```

but it raised that confgf module not found error, after I tried torch, pandas or other packages installed there, same error,  
only re, os this kind of module is ok.

the following code showed that confgf is installed.

```nohighlight
Installed /usr/local/Caskroom/miniconda/base/envs/confgf/lib/python3.8/site-packages/confgf-0.1.0-py3.8.egg
Processing dependencies for confgf==0.1.0
Finished processing dependencies for confgf==0.1.0

```

What could be the problem? Thank you!

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [February 5, 2022, 12:10pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/7 "2022-02-05T12:10:05Z")

</div>

> [@YitaoCai](#):
>
> ```julia
> ENV["JULIA_PYTHONCAL_EXE"] = "/usr/local/Caskroom/miniconda/base/envs/confgf/bin/python"
> 
> ```

There are two Ls in PythonCall 🙂

---

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 5, 2022, 3:47pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/8 "2022-02-05T15:47:53Z")

</div>

Interestingly, They gave the SAME result, after adding L  
import os is ok but import confgf or torch or other packages same Module not found Error.

---

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 5, 2022, 4:34pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/9 "2022-02-05T16:34:59Z")

</div>

I found you have a great package CondaPkg.jl, do I need to create the environment and install all things using your CondaPkg.jl?

---

<div class="post-metadata">

### Author: ![YitaoCai](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@YitaoCai](https://discourse.julialang.org/u/YitaoCai)
#### Post date: [February 5, 2022, 5:42pm UTC](https://discourse.julialang.org/t/how-to-use-python-library-in-julia/75644/10 "2022-02-05T17:42:24Z")

</div>

I reboot all of them and now it works, thank you very much!!!

BTW, can it use python command line?  
like

```nohighlight
python -u script/train.py --config_path ./config/qm9_default.yml
python -u script/train.py --config_path ./config/drugs_default.yml
python -u script/train.py --config_path ./config/iso17_default.yml

```
