Is there a way to lock the version of python packages

Julia has provided a way to lock the version of Julia packages which is great. However, I found I still need python packages to finish my works sometimes. And in order to use Julia in production, locking the version of dependencies is essential. And so far, I haven’t found any way to lock the version of python packages. Does anyone have some ideas about this?

1 Like

If you are OK with re-compiling PyCall everytime you switch the project/environment, you can simply point ENV["PYTHON"] to a python binary in virtualenv/venv: GitHub - JuliaPy/PyCall.jl: Package to call Python functions from the Julia language

If you want to quickly switch virtualenv/venv, the closest approximation is to use PYCALL_JL_RUNTIME_PYTHON: GitHub - JuliaPy/PyCall.jl: Package to call Python functions from the Julia language. But it has the restriction that you need to use the same libpython with which PyCall is built.

1 Like

The ENV[“PYTHON”] does help to lock the python version, and virtualenv can be switch by defining PYCALL_JL_RUNTIME_PYTHON. However, none of them help to lock the version of python packages. For example, ODBC.jl is too buggy so I have to use pyodbc, but I can’t specific the version of pyodbc anywhere in my julia module.

What do you mean? Combining poetry or pipenv with PYCALL_JL_RUNTIME_PYTHON seems to do exactly what you are talking about. For a concrete example, see:

Thank you so much for the example. I see how it works now. I was hoping I can specify the versions of python packages in Project.toml or another toml file and PyCall can set up the conda or pip virtual environment for me whether I have conda or pip installed.

Poetry locks Python packages.