How can I make a package run in its own environment

If I create a package Foo depending on Bar@0.1.0, and the default environment (say, v1.1) has Bar@0.2.0, how can I use the package Foo in the default environment?

Here’s what I did:

In the environment Foo, I ]add Bar@0.1.0. Clearly this creates a manifest.toml file with Bar@0.1.0. Then I switch back to the default environment v1.1 and then using Foo, Foo wouldn’t precompile due to compatibility issues (v0.1.0 vs v0.2.0).

My expectation is that Foo will run in its own environment described by its manifest.toml no matter what is the environment where Foo is used. However, this does not seem to be the case in my practice. Then, how can I simultaneously use two packages that have contradictory dependency requirements?

Hello @Chong_Wang Is this documentation useful
https://julialang.github.io/Pkg.jl/v1/environments/

I read the documentation before asking questions here.

You can’t. If you require a specific version of your dependencies you should include that information in the [compat] section in Project.toml, see https://julialang.github.io/Pkg.jl/v1/compatibility/

1 Like

So if two packages Foo1 and Foo2 have different requirements (say Bar@0.1.0 and Bar@0.2.0), I cannot use them at the same time?

Correct.

2 Likes