Using packages that were not added to the project's environment

New user of Pkg. I’ve noticed that If I open a new directory and create a new environment, i.e. ] activate ., I can run using <SomePackage> without adding it, as long as <SomePackage> is in my general environment, and Project.toml remains unchanged. I’m pretty sure that at some point this will cause me to use packages without adding them and documenting them in Project.toml. Of course, a solution is having no packages in my general environment, but I feel that is inconvenient, and I prefer not having to create environments for small and quick stuff. Is there a reason it is so? Is there some other solution?

I think you should add packages to the environment when they are dependencies of the current project, and only in that case. Otherwise just use using them. This is very typical, you have one package that depends on other packages, but to test it, for example, you need other packages that are not necessarily dependencies.

There is no need to create an environment for every little thing, just be careful when using dev SomePackage while in the general environment, usually on the “main” environment one wants the stable versions of the packages.

1 Like

Thanks, now it makes more sense why should you be able to use packages without adding them. However, I’m still a bit worried about forgetting to add packages which are dependencies to my project, since I can just use them without adding them and I won’t notice. I guess I should just be watchful for that.

1 Like

You can set JULIA_LOAD_PATH to @ to only allow loading packages from the active project. You can configure this automatically on the project level using direnv. I wrote a post about that: