我在 linux 机器上设置了 anaconda 虚拟环境。
该dotenv
模块没有安装,所以我尝试安装它。它安装成功:
(virt_env_01) [jm@etl01 testing]$ conda install -c conda-forge python-dotenv
## Package Plan ##
environment location: /home/jm/anaconda3/envs/virt_env_01
added / updated specs:
- python-dotenv
...
Downloading and Extracting Packages
certifi-2018.4.16 | 142 KB | ############################################### | 100%
python-dotenv-0.8.2 | 18 KB | ############################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
但是,当我尝试使用它运行 python 脚本时,我收到一条错误消息,提示找不到模块。
(virt_env_01) [jm@etl01 testing]$ pytest sql_server_tests.py
platform linux -- Python 3.6.3, pytest-3.2.1, py-1.4.34, pluggy-0.4.0
...
Traceback:
sql_server_tests.py:3: in <module>
import dotenv
ModuleNotFoundError: No module named 'dotenv'
有人可以解释我做错了什么吗?
编辑:
我在上面运行 Pytest。所以我尝试了 Python,它工作正常。pytest可以安装在虚拟环境之外吗?我不知道这一切是如何运作的。