Spyder下的Conda与PIP

发布于 2025-02-03 05:44:56 字数 2332 浏览 3 评论 0 原文

我有一个关于Conda与PIP虚拟环境的2部分问题。我找到了有关答案的很好的信息 pip and conda?,但仍然有一些不清楚的东西。

我有一个给定的Python项目(例如PR),我需要在Linux服务器(例如S)上安装并进一步开发使用Anaconda安装Python。现在,PR的用法/安装说明告诉我使用Python创建虚拟环境和PIP来安装所有软件包。也就是说,

python3 -m Venv pr

pip install -edistable -edist.abled。(末尾包含的点),

根据” pip install-edistable-editable ./“ vs” vs“ python setup.py develop” 后者读取文件 setup.py (PR中包含),其中包含一个功能设置(...)带有选项 install_requires 列出所有必需的软件包并自动安装它们。我已经在自己的计算机上(没有Conda)对此进行了测试,并且效果很好。至少没有错误消息。

现在,我需要进一步开发有关S的PR。我的问题第1部分:我可以使用conda而不是pip来创建和更新虚拟环境吗?如果是,conda命令替换 pip install -edectible。是什么?我很肯定,以后我还需要安装其他软件包。我担心Conda/Pip之间的冲突。

在S上,我有Spyder,没有其他Python Ides。我从未使用过Spyder,但是我对Pycharm(Windows)和VS代码(Linux)非常熟悉,因此我认为与Spyder一起调试将与这些调试相似。我的问题第2部分(与第1部分有关):如果我必须使用PIP安装软件包,Spyder会看到这些吗?还是只能看到Conda安装的软件包?

编辑/更新):谢谢Carlos的评论。我继续我的问题:

虚拟环境(VE)

conda create PR_venv
conda activate PR_venv

我使用Conda安装PIP

conda install pip

创建并激活了使用(此升级的PIP)并安装了其他几个软件包的 ,包括较新版本的Python)。立即使用PIP安装了PR及其所需的软件包

pip install -e .

,如果我从终端进行交互式VE中运行PR软件包,则一切正常。我想从Spyder内部做同样的事情,以获取IDE调试能力。

当我启动Spyder时,打开一个要运行的python文件,单击“运行”按钮,它会在导入语句中崩溃。 Spyder看不到已安装的软件包。它只能看到本地软件包PR,但没有PIP安装的软件包为此VE。

我不确定这里的正确问题是什么?我很困惑与Spyder/Jupyter/Ipython有何关系?我在Conda文档中找不到有关此信息的信息。 我从Spyder中找不到有关VES的任何文档。我是否必须以某种方式重新安装Spyder内部的包装(如何?)?似乎毫无意义,因为软件包已经安装了。

编辑/更新2 ):使我更加困惑:Spyder以 是一个独立的程序 Python包。那么,我是否必须重新安装Spyder在VE(?!)内进行

conda activate PR_venv
conda install spyder

任何澄清。我一直认为IDE是独立的程序,仅此而已。这个间谍的设置使我的大脑变成了椒盐脆饼。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-黛色若梦 2025-02-10 05:44:56

spyder维护者在这里)关于您的问题:

我可以使用conda而不是pip创建和更新虚拟环境吗?

是的,你可以。请参阅在这里了解Conda为管理环境提供的功能。

如果是,conda命令替换 pip install -edertip。

康达(Conda)不能为该命令提供良好的替换。但是,只要您在运行前与Conda安装了所有包装依赖关系,您仍然可以在Conda环境中使用它。这将避免混合Conda和Pip套件,这通常会导致效果非常糟糕。

如果我必须使用PIP安装软件包,Spyder会看到这些吗?还是只能看到Conda安装的软件包?

Spyder可以在没有问题的情况下与PIP和CONDA套餐一起使用。只需确保不混合它们(如上所述),就可以了。此外,请阅读我们的文档<我们的文档< /a>学习如何将本地Spyder实例连接到远程服务器。

(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.

素罗衫 2025-02-10 05:44:56

第1部分:是的,我可以使用conda创建VE和PIP来安装

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

最后一行,显示了哪些软件包由 conda 以及 pip (显示为 PYPI

第2部分:Spyder默认情况下看不到软件包。需要做两件事:

conda install spyder-kernels

开放Spyder and Tools&gt;偏好&gt; Python口译员&GT;使用以下解释器&gt; [通往Ve Python命令的完整路径]

重新启动Spyder。现在可以看到包装。

(编辑:)此链接很棒: https://github.com/spyder-ide/spyder/wiki/working-with-packages-and-environments-invironments-in-spyder

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文