简体   繁体   English

从Windows上的conda环境运行python

[英]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. 下面是运行用p​​ython 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)时 -

  1. Activate the environment - activate py27 激活环境 - activate py27
    This works on windows. 这适用于Windows。 In linux/mac type source activate py27 Prompt should change to (py27) . linux / mac类型的source activate py27提示符应该改为(py27)
  2. Navigate to the directory where you created your python.py file. 导航到您创建 python.py文件的目录。
    If you have not created any .py file, simply open a notepad and rename it as python.py . 如果您尚未创建任何.py文件,只需打开一个记事本并将其重命名为python.py Write your code. 写下你的代码。 Right now for testing purpose, simply write print "Hello" . 现在出于测试目的,只需编写print "Hello"
  3. Now in the terminal just enter python.py or the name of python file. 现在在终端只需输入python.py或python文件的名称。 It should run and print Hello. 它应该运行并打印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.

相关问题 使用特定的 conda 虚拟环境将 Python 程序作为 Windows 服务运行 - Running Python Program as Windows Service with a specific conda virtual environment 检测 Python 是否在 Conda 环境中运行 - Detect if Python is running in a Conda environment conda install -c conda-forge python-pdal解决环境: 在运行Windows 10时挂起 - conda install -c conda-forge python-pdal Solving environment: | hangs when running windows 10 康达环境从 windows 到 linux - conda environment from windows to linux 从 linux 到 windows 的 Conda 环境 - Conda environment from linux to windows Conda (Python) 虚拟环境不能从 Windows 移植到 Linux - Conda (Python) Virtual Environment is not Portable from Windows to Linux 从另一个 Conda 环境中的脚本中在 Conda 环境中运行脚本 - Running script in Conda environment from within script in another Conda environment vscode python interactive window timed out on running python script on other conda environment 除了基础环境 - Vscode python interactive window timed out on running python script on other conda environment apart from base environment Windows上的Conda Python环境缺少DLL文件 - Conda Python environment missing DLL file on Windows Anaconda/conda/python/Windows:如何启动和激活 conda 环境? - Anaconda/conda/python/Windows: how to start and activate a conda environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM