我已将keras
安装到我的Anaconda虚拟环境中,但是无法导入该模块:
$ conda list | grep keras
keras 2.2.4 py37_1 conda-forge
keras-applications 1.0.8 py_0
keras-preprocessing 1.1.0 py_1
keras-retinanet 0.5.0 pypi_0 pypi
$ python
Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'keras'
可能有什么不对?
答案 0 :(得分:0)
最好的选择是在虚拟环境中使用venv。有关说明:
1)克隆存储库后,将cd
放入存储库并运行命令:python3 -m venv venv
This will create the virtual environment. Make sure to name it venv because the .gitignore file
has been initialized to ignore it by default.
2)通过运行以下命令来激活虚拟环境:source venv/bin/activate
3)要下载所需的软件包,只需运行:pip install -r requirements.txt
This will go to the requirements file that is already generated in the repo and download any dependecies.
4)添加任何软件包之后,请确保通过运行以下命令来更新requirements.txt文件:pip freeze > requirements.txt
5)您随时可以运行deactivate
离开虚拟环境。
1)克隆存储库后,将cd
放入存储库并运行命令:python -m venv venv
This will create the virtual environment. Make sure to name it venv because the .gitignore file
has been initialized to ignore it by default.
2)通过运行以下命令来激活虚拟环境:venv\Scripts\activate.bat
To activate the virtual environment inside of a code editor's bash, run: venv\Scripts\activate.ps1
3)要下载所需的软件包,只需运行:pip install -r requirements.txt
4)添加任何程序包后,请确保通过运行以下命令来更新requirements.txt文件:pip freeze
然后将它们粘贴到requirements.txt
文件中。
5)您随时可以运行deactivate
离开虚拟环境。
最后,只需键入pip install keras