Is there a way to keep a Python 2 and Python 3 version of PyCall in two separate environments?

I’ve got separate projects which use Python 2 or Python 3 dependencies via PyCall. I want to avoid having to recompile everything whenever I need to switch Python versions, so I was hoping I could put a Python-2-built PyCall in one environment and a Python-3-built one in another.

I tried doing this but I think they share the same build so it doesn’t work. I also tried making the versions of PyCall be different (1.18.5 vs 1.18.4) hoping this makes it so things aren’t shared across environments, and now the version of Python is different in each environment, but every time I switch environments, I still get a precompile, which defeats the purpose.

Anyone have any ideas on if I can do this? (or any better ways to be switching between Python 2 and 3?) Thanks.

1 Like

I think using separate depots for each environment should work. You can do this by setting LOAD_PATH before for you switch environments.

Sadly this is not directly supported. It would require some help from Pkg.jl. See:

I think you need to set DEPOT_PATH (environment variable: JULIA_DEPOT_PATH) instead for isolating cache and PyCall setup.


Yes, thats right. I always mix those two variables :sweat_smile:. It would indeed be nice to have a supported solution.

1 Like

How about building Julia 2 times and then each Julia version being linked to a specific Python distribution? Quite ugly, but I guess it would work.