6

I have been working on a project in PyCharm within a Conda environment. Now I would like to start a new project and make it use the same conda environment.

When I first created the initial environment in PyCharm, I did not select the checkbox that mentions make available to all projects, so naturally it doesn't show up in the list of existing environments in PyCharn. After googling and sifting through the PyCharm interpreter settings I could not find a solution.

How do I make the already existing conda environment avilable to other projects? Sorry if this is a dumb question.

Ahmad Moussa
  • 876
  • 10
  • 31

3 Answers3

6

Go to Settings/Preferences | Project | Project Interpreter and do as shown on the screenshot for you environment: enter image description here

Sergey K.
  • 1,855
  • 9
  • 12
3

I think there are two approaches one could take at the Conda level. Which you choose depends on whether you want subsequent changes to the env to affect both (Alias Option) or if you want to keep them separate, but just use the existing one as a starting point (Clone Option).

In either case, you need to locate where PyCharm has created the env. Using conda env list should list it, where it would appear without a name, but still show the prefix (directory). You could also locate it through PyCharm's Python Console by running

import sys
print(sys.prefix)

Let's assume the prefix is /some/other/path/myenv.

Alias Option

If you want the env to be generally available as a nameable env, then you can create an alias to the prefix in the standard envs folder. If you want to name the env myenv then you could do

ln -s /some/other/path/myenv /your/path/to/anaconda/envs/myenv

This would make it discoverable and also you could do conda activate myenv outside of PyCharm to use it.

Clone Option

In this case, you will create a new env, but link to exactly the same packages that the original env is linked to.

conda create -n myenv --clone /some/other/path/myenv

Add Existing

A third option would be to simply locate the Python interpreter through PyCharm's Add existing Conda env.. dialog.

merv
  • 67,214
  • 13
  • 180
  • 245
  • Does cloning only links but does not duplicate the packages (in as take up more storage space) then that could be a potential fix. Thank you. – Ahmad Moussa Nov 28 '19 at 03:22
  • @AhmadMoussa the cloning will still involve some copying, but Conda tries to minimize it as much as possible – merv Nov 28 '19 at 03:34
1

Follow these steps:

  1. Open settings for your new project.
  2. Open Python Interpreter settings.

Step2

  1. Press "Show All..." in the Python Interpreters list.

Step3

  1. Unselect the "Hide virtual environments associated with other projects" button in the left corner.

Step4

Done! Now you can use a conda environment that was created for another project!

Usr Ustym
  • 11
  • 2