Python 如何在创建虚拟环境时自动安装pygame?

Python 如何在创建虚拟环境时自动安装pygame?,python,pygame,virtualenv,Python,Pygame,Virtualenv,我正在创建一个虚拟环境testenv来运行一些python项目。这是我的environment.yml文件: name: testenv channels: - !!python/unicode 'defaults' dependencies: - python=3.5 - pip==9.0.1 - numpy==1.12.0 - jupyter==1.0 - matplotlib==2.0.0 - scikit-learn==0.18.1 - scipy==0.19.0 - pandas=

我正在创建一个虚拟环境
testenv
来运行一些python项目。这是我的
environment.yml
文件:

name: testenv
channels:
- !!python/unicode
  'defaults'
dependencies:
- python=3.5
- pip==9.0.1
- numpy==1.12.0
- jupyter==1.0
- matplotlib==2.0.0
- scikit-learn==0.18.1
- scipy==0.19.0
- pandas==0.19.2
- pip:
  - tensorflow==1.1.0
  - keras==2.0.4
  - plotly==2.7.0
我想将
pygame
添加到此环境中。但是,如果我将
pygame==1.9.4
添加到
dependencies
pip
,则虚拟环境的创建将失败:

conda env create
因此,我应该
source激活testenv
,然后手动安装
pygame
,但这不是很方便

brew install sdl sdl_image sdl_mixer sdl_ttf portmidi
pip install pygame
是否有人尝试过在虚拟环境中以自动方式安装
pygame

创建环境:

conda env create -f environment.yml
要生成您的yml,请执行以下操作:

conda env export > environment.yml

更多信息请参见

什么是
-f
?请您解释一下我应该如何更改文件
environment.yml
?好的,我只是手动安装了它,并按照您的建议导出了它。美好的谢谢。-f是强制安装所有软件包的选项