[英]Running python from a conda environment on windows
I have decided to have both python 2 and 3 installed on my Windows PC. 我决定在我的Windows PC上安装python 2和3。 Python 3 was included with Anaconda, and works flawlessly after the installation of Anaconda.
Python 3包含在Anaconda中,并且在Anaconda安装后可以完美运行。
After having created successfully a python 2 environment: 成功创建python 2环境后:
conda create --name py27 python=2.7
I noticed that no python.py file has been created in C:\\Users\\Hélain\\IT\\Anaconda3\\envs\\py27 . 我注意到在C:\\ Users \\Hélain\\ IT \\ Anaconda3 \\ envs \\ py27中没有创建python.py文件。
Typing python in my terminal launches my python 3 python and py27 is not considered a command. 在我的终端中键入python启动我的python 3 python并且py27不被视为命令。 Activating or deactivating the environment does no change this behavior.
激活或停用环境不会改变此行为。
Result of typing python : 键入python的结果:
C:\Users\Hélain>activate py27
Deactivating environment "C:\Users\Hélain\IT\Anaconda3"...
Activating environment "C:\Users\Hélain\IT\Anaconda3\envs\py27"...
[py27] C:\Users\Hélain>python
Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 24 2014, 18:32:42) [MSC v.1
600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
How do I run python with my environment's version and packages? 如何使用我的环境版本和软件包运行python?
In your terminal type: 在您的终端类型中:
activate py27
The prompt should change to (py27)
. 提示应更改为
(py27)
。
Now you can install packages in this environment. 现在您可以在此环境中安装软件包。 For example:
例如:
conda install jupyter matplotlib
Launch Python from this terminal with: 从这个终端启动Python:
python
Below are the steps to run python code written in python 2.7 syntax. 下面是运行用python 2.7语法编写的python代码的步骤。
In order to run any python file (for example, as you mention python.py) after successfully creating a conda environment is- 为了在成功创建conda环境后运行任何python文件(例如,当你提到python.py)时 -
activate py27
activate py27
source activate py27
Prompt should change to (py27)
. source activate py27
提示符应该改为(py27)
。 python.py
file. python.py
文件的目录。 .py
file, simply open a notepad and rename it as python.py
. .py
文件,只需打开一个记事本并将其重命名为python.py
。 Write your code. print "Hello"
. print "Hello"
。 python.py
or the name of python file. python.py
或python文件的名称。 It should run and print Hello. I am not that experienced to know much about the python version conflict you encountered while running the python command. 我不太了解运行python命令时遇到的python版本冲突。 But you should check the github repo for issues related to conda for more information on this.
但是您应该查看github repo以了解与conda相关的问题,以获取更多相关信息。 It may be a bug.
这可能是一个错误。
I think you mean python.exe
in your environment? 我认为你的意思是你的环境中的
python.exe
? From my understanding, all your Pycharm projects can point to the same Anaconda interpreter (stored outside the environment folders) and then to propagate an envrionment change to Pycharm, you just need to do it from the Conda prompt 根据我的理解,你所有的Pycharm项目都可以指向相同的Anaconda解释器(存储在环境文件夹之外),然后将环境变化传播到Pycharm,你只需要从Conda提示符中做到这一点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.