我正在使用 anaconda 和 python 3.8。现在我的一些代码需要使用 python 2 运行。因此我在 conda 中创建了一个单独的 python 2.7 环境,如下所示:
之后,我安装了spyder,然后启动器spyder amd SPYDER显示我仍在使用python 3.8
如何在新环境下在spyder中使用python 2.7?
谢谢
conda create -n py27 python=2.7 ipykernel
conda activate py27
pip install spyder
Run Code Online (Sandbox Code Playgroud)
小智 10
根据此处的文档,这应该创建一个安装了spyder的python2.7虚拟环境(2021年4月29日)。我验证了spyder版本3.3.6与python2.7兼容
conda create -y -n py27 python=2.7 spyder=3.3.6
Run Code Online (Sandbox Code Playgroud)
但是,由于未能捕获冲突,我无法spyder在该环境中运行。asanganuwan在这个Spyder Github Issue页面上显示的解决方法也对我有用py27conda
找到了在 python 2.7 上使用 Spyder 的解决方法。
Run Code Online (Sandbox Code Playgroud)setup two virtual environments for Python 2.7 and 3.6. Launce anaconda navigator and install spyder 3.3.6 on both the environments Launch spyder on the environment with Python 3.6 Preferences-->Python Interpreter --> set the Python path for 2.7 Restart Spyder Done!
所以我的建议是下次运行
conda create -y -n py36 python=3.6 spyder=3.3.6
conda activate py36
spyder
Run Code Online (Sandbox Code Playgroud)
并遵循 asanganuwan 的最后三个指示。
此外,您还应该conda尽可能多地使用包管理器,因为它可以更智能地管理需求。pip install spyder当我激活环境后尝试使用时,它警告版本冲突并且无法启动。