1

I created a new anaconda enviroment using "conda env create -n TestOne" which created a new Python 3.5 environment with no packages installed.

I am using PTVS with Visual Studio and I manually added the new environment and paths as per the following: http://kronoskoders.logdown.com/posts/73461-using-anaconda-and-ptvs

I then activated the environment and ran in the command prompt: conda install -c conda-forge pyside

Now when I run "pip list" it is different then "conda list" and it appears that the Python Environments->TestOne in Visual Studio shows the pip list. Is there any way to get an accurate list of what is actually installed using anaconda?

If I go to Tools->Python Tools->Python Environments, select my created TestOne environment, select Intellisense from the drop down and then Refresh DB I see PySide is in the list and it is available in Intellisense.

It is a bit confusing to me just getting into Python development that the setup appears to work opposite with this vs something like C#. With C# you download and reference libraries per project where as with Python you have environments with libraries as part of them that are available to every project after the first install.

Is there any way for Visual Studio to show the conda list instead so I can easily see what is actually installed?

Dru
  • 357
  • 4
  • 13
  • I notice in the tables that are output there is a column that lists items lite py35_ and vc14_. Conda list shows everything but pip list shows only the py35_ items. I do not understand enough about how pip list works to see why it skips the other modules. Maybe it is a path thing since anaconda has virtual environments that I am using – Dru Dec 21 '16 at 17:14

1 Answers1

1

PTVS (Python Tools for Visual Studio) doesn't yet fully-support Conda, but I understand it is on the roadmap, so we can hope that support will improve.

Currently, PTVS always uses pip to install new packages and does not automatically detect conda environments. That doesn't mean you cannot use them though.

I think for your scenario, you probably want to create a conda environment within the project itself, so that each project can have its own unique environment containing the correct packages for that particular project (just like nuget).

So instead of specifying an environment name, specify a prefix. Then instead of installing the environment globally it will install it at the prefix location, which may be a relative path.

From a command prompt with your root environment on the path, create a new environment called env (or another name of your choice) in the root directory of your project and activate it:

cd myproject
conda create -p env python=3.6
activate <full path to project>\env

To get Visual Studio to recognise and use this environment:

  1. Open the Python Environments window and select + Custom....
  2. Set the Interpreter path to point to the python.exe file inside env.
  3. Select Auto Detect and then Apply to automatically complete the other fields.
  4. Find your project in Solution Explorer, right-click Python Environments, and choose Add/Remove Python Environments. In the list, tick env. The selected enviroment in the Solution Explorer should now be env.

When you check your project into version control, don't add the env directory. Instead, export the environment file and add that:

conda env export > environment.yml

The environment can be exactly recreated with:

conda create -f environment.yml -p env

Don't forget to update the environment.yml file every time you install, upgrade, or remove a package.

Finally, remember to use a command prompt with this enviroment activated when you install new packages via conda - don't use the Visual Studio Packages interface because this will install them globally using pip.

Ian Goldby
  • 5,609
  • 1
  • 45
  • 81