0

I have a 2-part question about conda vs. pip virtual environments. I found great information on the answers What is the difference between pip and conda? and Does Conda replace the need for virtualenv? but still have something unclear.

I have a given python project (say PR) that I need to install and further develop on a linux server (say S) where python is installed with anaconda. Now, the usage/installation instructions of PR tell me to use python to create virtual environment and pip to install all packages. That is,

python3 -m venv PR

pip install --editable . (the dot included at the end)

According to "pip install --editable ./" vs "python setup.py develop" the latter reads the file setup.py (included in PR) which contains a function setup(...) with option install_requires listing all the required packages and installs them automatically. I have tested this on my own computer (which does not have conda) and it works fine. At least no error messages.

Now I need to further develop PR on S. My question Part 1: can I use conda instead of pip to create and update virtual environment? If yes, what would be the conda command replacing pip install --editable . ? I'm positive I will later need to install other packages as well. I'm worried about conflicts between conda/pip.

On S, I have Spyder and no other python IDEs. I have never used Spyder but I'm very familiar with PyCharm (Windows) and VS Code (Linux) so I assume debugging with Spyder will be similar to those. My question Part 2 (tied to Part 1): if I have to use pip to install packages, does Spyder see those? Or can it only see conda-installed packages?

(Edit/update): Thank you Carlos for comments. I continue my question:

I created and activated the virtual environment (VE) with conda

conda create PR_venv
conda activate PR_venv

Installed pip with

conda install pip

(this upgraded pip and installed several other packages too, including newer version of python). Installed PR and its required packages with pip

pip install -e .

Now, if I run the PR package inside this active VE interactively from the terminal, everything works fine. I would like to do the same from within spyder, to get the IDE debugging abilities in my hand.

When I start spyder, open a python file to be run, click "Run" button, it crashes in the import statements. Spyder cannot see the installed packages. It can see only the local package PR but none of the packages installed by pip for this VE.

I am not sure what is the correct question here; I'm confused how are conda VEs related to spyder/jupyter/ipython ? I cannot find information in the conda documents about this. I cannot find from spyder documents anything about VEs. Do I have to somehow re-install the packages (how?) inside Spyder? It seems pointless because the packages are installed already.

(Edit/Update 2): The information on https://docs.spyder-ide.org/current/installation.html makes me even more confused: Spyder is presented as both a stand-alone program and as a python package. So do I have to re-install Spyder inside the VE(?!) with

conda activate PR_venv
conda install spyder

Any clarification would be appreciated. I have always thought that the IDEs are stand-alone programs and that's it. This Spyder setup twists my brains into pretzel.

user9393931
  • 177
  • 2
  • 9
  • 1
    Please rephrase your question. 1) "should I use conda or python/pip to create and update virtual environment?" is only opinion based. 2) Please ask only one question at once – FlyingTeller May 30 '22 at 10:50
  • @FlyingTeller Thanks, I have reformulated the first part of the question. But I think this really is one question with 2 parts: they are so intertwined that I don't see sense splitting them into 2 separate posts. – user9393931 May 30 '22 at 11:28

2 Answers2

1

(Spyder maintainer here) About your questions:

can I use conda instead of pip to create and update virtual environment?

Yes, you can. Please see here to learn about the functionality offered by conda for managing environments.

If yes, what would be the conda command replacing pip install --editable . ?

Conda doesn't offer a good replacement for that command. However, you can still use it in a conda environment, as long as all you've installed all your package dependencies with conda before running it. That would avoid mixing conda and pip packages, which usually leads to really bad results.

if I have to use pip to install packages, does Spyder see those? Or can it only see conda-installed packages?

Spyder can work with pip and conda packages without problems. Just make sure of not mixing them (as I said above) and you'll be fine. In addition, please read our documentation to learn how to connect a local Spyder instance to a remote server.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
1

Part 1: yes I can use conda to create VE and pip to install packages

conda create PR_venv
conda activate PR_venv
conda install pip
pip install --editable .
conda list

The last line shows which packages are installed by conda and which by pip (shown as pypi)

Part 2: spyder by default cannot see the packages. Need to do two things:

conda install spyder-kernels

Open Spyder and Tools > Preferences > Python Interpreter > Use the following interpreter > [full path to VE python command]

Restart Spyder. Now it can see the packages.

(Edit:) this link is great: https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder

user9393931
  • 177
  • 2
  • 9