gpt4 book ai didi

python-3.x - Spyder 控制台找不到 keras 模块

转载 作者:行者123 更新时间:2023-12-03 11:21:17 26 4
gpt4 key购买 nike

我有一个用 Anaconda 创建的虚拟环境。激活后,我可以启动 python3 shell 并导入 keras 库,我收到以下警告,但除此之外它似乎可以正常工作。

/home/ryan/anaconda3/envs/spyderudemy/lib/python3.6/site-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type. from ._conv import register_converters as _register_converters Using TensorFlow backend.

现在,如果在我的终端中激活了虚拟环境并从该终端启动 Spyder IDE,我将无法访问 IPython 控制台中的 keras 库。具体来说,导致我出现问题的导入是:

from keras.models import Sequential

IPython shell 中的输出是:

ModuleNotFoundError: No module named 'keras'

我使用的是 Ubuntu 16.04,当我启动 Spyder 时,它显示在控制台的顶部:

Python 3.6.5 |Anaconda custom (64-bit)| (default, Apr 26 2018, 13:46:40)

如果我执行,从我的普通 bash 终端

python3 -c 'import sys, pprint; pprint.pprint(sys.path)'

我得到:

['', '/home/ryan/anaconda3/envs/spyderudemy/lib/python36.zip', '/home/ryan/anaconda3/envs/spyderudemy/lib/python3.6', '/home/ryan/anaconda3/envs/spyderudemy/lib/python3.6/lib-dynload', '/home/ryan/anaconda3/envs/spyderudemy/lib/python3.6/site-packages']

尽管我认为 Tensorflow 应该包含在 Anaconda 软件包中,但由于它无法正常工作,我还是使用 pip3 将其安装在环境中,如下所示:

sudo pip3 install --upgrade tensorflow

我使用 sudo 是因为我遇到了权限错误,而且我认为输出看起来还不错:

The directory '/home/ryan/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/ryan/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting tensorflow Downloading https://files.pythonhosted.org/packages/6d/dc/464f59597a5a8282585238e6e3a7bb3770c3c1f1dc8ee72bd5be257178ec/tensorflow-1.8.0-cp35-cp35m-manylinux1_x86_64.whl (49.1MB) 100% |████████████████████████████████| 49.1MB 33kB/s Collecting tensorboard<1.9.0,>=1.8.0 (from tensorflow) Downloading https://files.pythonhosted.org/packages/59/a6/0ae6092b7542cfedba6b2a1c9b8dceaf278238c39484f3ba03b03f07803c/tensorboard-1.8.0-py3-none-any.whl (3.1MB) 100% |████████████████████████████████| 3.1MB 466kB/s Collecting wheel>=0.26 (from tensorflow) Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB) 100% |████████████████████████████████| 51kB 3.3MB/s Collecting numpy>=1.13.3 (from tensorflow) Downloading https://files.pythonhosted.org/packages/43/17/cd9fa14492dbef2aaf22622db79dba087c10f125473e730cda2f2019c40b/numpy-1.14.5-cp35-cp35m-manylinux1_x86_64.whl (12.1MB) 100% |████████████████████████████████| 12.1MB 131kB/s Collecting gast>=0.2.0 (from tensorflow) Collecting protobuf>=3.4.0 (from tensorflow) Downloading https://files.pythonhosted.org/packages/11/c4/8a35f5af5f26040ae7f3d521875e43429d2955d598fa3f2d0b6b88133bb1/protobuf-3.6.0-cp35-cp35m-manylinux1_x86_64.whl (7.1MB) 100% |████████████████████████████████| 7.1MB 223kB/s Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python3.5/dist-packages (from tensorflow) Collecting termcolor>=1.1.0 (from tensorflow) Collecting absl-py>=0.1.6 (from tensorflow) Collecting astor>=0.6.0 (from tensorflow) Downloading https://files.pythonhosted.org/packages/b2/91/cc9805f1ff7b49f620136b3a7ca26f6a1be2ed424606804b0fbcf499f712/astor-0.6.2-py2.py3-none-any.whl Collecting grpcio>=1.8.6 (from tensorflow) Downloading https://files.pythonhosted.org/packages/c6/b8/47468178ba19143e89b2da778eed660b84136c0a877224e79cc3c1c3fd32/grpcio-1.12.1-cp35-cp35m-manylinux1_x86_64.whl (9.0MB) 100% |████████████████████████████████| 9.0MB 182kB/s Collecting markdown>=2.6.8 (from tensorboard<1.9.0,>=1.8.0->tensorflow)
Downloading https://files.pythonhosted.org/packages/6d/7d/488b90f470b96531a3f5788cf12a93332f543dbab13c423a5e7ce96a0493/Markdown-2.6.11-py2.py3-none-any.whl (78kB) 100% |████████████████████████████████| 81kB 3.8MB/s Collecting html5lib==0.9999999 (from tensorboard<1.9.0,>=1.8.0->tensorflow) Collecting bleach==1.5.0 (from tensorboard<1.9.0,>=1.8.0->tensorflow) Downloading https://files.pythonhosted.org/packages/33/70/86c5fec937ea4964184d4d6c4f0b9551564f821e1c3575907639036d9b90/bleach-1.5.0-py2.py3-none-any.whl Collecting werkzeug>=0.11.10 (from tensorboard<1.9.0,>=1.8.0->tensorflow) Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB) 100% |████████████████████████████████| 327kB 1.8MB/s Collecting setuptools (from protobuf>=3.4.0->tensorflow) Downloading https://files.pythonhosted.org/packages/7f/e1/820d941153923aac1d49d7fc37e17b6e73bfbd2904959fffbad77900cf92/setuptools-39.2.0-py2.py3-none-any.whl (567kB) 100% |████████████████████████████████| 573kB 1.5MB/s Installing collected packages: markdown, numpy, html5lib, wheel, setuptools, protobuf, bleach, werkzeug, tensorboard, gast, termcolor, absl-py, astor, grpcio, tensorflow Found existing installation: numpy 1.13.3 Uninstalling numpy-1.13.3: Successfully uninstalled numpy-1.13.3 Found existing installation: html5lib 0.999 Uninstalling html5lib-0.999: Successfully uninstalled html5lib-0.999 Found existing installation: wheel 0.29.0 Uninstalling wheel-0.29.0: Successfully uninstalled wheel-0.29.0 Found existing installation: setuptools 20.7.0 Uninstalling setuptools-20.7.0: Successfully uninstalled setuptools-20.7.0 Found existing installation: protobuf 3.4.0 Uninstalling protobuf-3.4.0: Successfully uninstalled protobuf-3.4.0 Successfully installed absl-py-0.2.2 astor-0.6.2 bleach-1.5.0 gast-0.2.0 grpcio-1.12.1 html5lib-0.9999999 markdown-2.6.11 numpy-1.14.5 protobuf-3.6.0 setuptools-39.2.0 tensorboard-1.8.0 tensorflow-1.8.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.31.1 You are using pip version 9.0.1, however version 10.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.

如果有人对这个问题有任何建议,我将永远感激不已。

最佳答案

Now if in my terminal I have the virtual env activated and [...].

那你是不是在虚拟环境中安装了keras?如果没有,请尝试按照使用 Anaconda 安装部分进行操作。

应该是这样的:

(your_env_name) conda install your_package_name

关于python-3.x - Spyder 控制台找不到 keras 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50937489/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com