2017-01-19 4 views
0

これをどのように修正できたか考えてみてください。仮想EnvでKerasをインポートできない

[email protected]:~$ python3 
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import keras 
Using TensorFlow backend. 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally 
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally 
[email protected]:~$ source /usr/local/bin/virtualenvwrapper.sh 
[email protected]:~$ workon cv2 
(cv2) [email protected]:~$ python 
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import keras 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named 'keras' 

UPDATE:

$ sudo pip install keras 
The directory '/home/mona/.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/mona/.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 keras 
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning. 
    SNIMissingWarning 
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning. 
    InsecurePlatformWarning 
    Downloading Keras-1.2.0.tar.gz (167kB) 
    100% |████████████████████████████████| 174kB 2.1MB/s 
Collecting theano (from keras) 
    Downloading Theano-0.8.2.tar.gz (2.9MB) 
    100% |████████████████████████████████| 2.9MB 346kB/s 
Requirement already satisfied: pyyaml in /usr/lib/python2.7/dist-packages (from keras) 
Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from keras) 
Requirement already satisfied: numpy>=1.7.1 in /usr/local/lib/python2.7/dist-packages (from theano->keras) 
Requirement already satisfied: scipy>=0.11 in /usr/lib/python2.7/dist-packages (from theano->keras) 
Installing collected packages: theano, keras 
    Running setup.py install for theano ... done 
    Running setup.py install for keras ... done 
Successfully installed keras-1.2.0 theano-0.8.2 
(cv2) [email protected]:~/computer_vision/opencv-3.2.0/build$ python 
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import keras 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named 'keras' 

(cv2) [email protected]:~/computer_vision/opencv-3.2.0/build$ sudo pip3 install keras 
Requirement already satisfied (use --upgrade to upgrade): keras in /usr/local/lib/python3.4/dist-packages 
Requirement already satisfied (use --upgrade to upgrade): theano in /usr/local/lib/python3.4/dist-packages (from keras) 
Requirement already satisfied (use --upgrade to upgrade): pyyaml in /usr/local/lib/python3.4/dist-packages (from keras) 
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python3.4/dist-packages (from keras) 
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.1 in /usr/local/lib/python3.4/dist-packages (from theano->keras) 
Requirement already satisfied (use --upgrade to upgrade): scipy>=0.11 in /usr/local/lib/python3.4/dist-packages (from theano->keras) 
Cleaning up... 
(cv2) [email protected]:~/computer_vision/opencv-3.2.0/build$ sudo pip3 install --upgrade keras 
Requirement already up-to-date: keras in /usr/local/lib/python3.4/dist-packages 
Requirement already up-to-date: theano in /usr/local/lib/python3.4/dist-packages (from keras) 
Requirement already up-to-date: pyyaml in /usr/local/lib/python3.4/dist-packages (from keras) 
Requirement already up-to-date: six in /usr/local/lib/python3.4/dist-packages (from keras) 
Requirement already up-to-date: numpy>=1.7.1 in /usr/local/lib/python3.4/dist-packages (from theano->keras) 
Requirement already up-to-date: scipy>=0.11 in /usr/local/lib/python3.4/dist-packages (from theano->keras) 
Cleaning up... 
(cv2) [email protected]:~/computer_vision/opencv-3.2.0/build$ python 
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import keras 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named 'keras' 
+0

あなたは '内外にvirtualenvのfreeze'ピップの出力をポストてもらえますか? –

答えて

-1

cv2環境を作成するとき、それは可能です、あなたは--system-site-packagesフラグとそれを作成していませんか? そうでない場合、virtualenvの中にはいつでもpip install kerasを入れることができます。

+0

アップデートをご覧ください。残念ながら、それは動作しませんでした! –

+0

'--system-site-package'でvirtualenvを使うと目的が崩れますか? –

+0

@HaraldNordgren '--system-site-packages'では、システムにインストールされているパッケージを使用できますが、環境に新しいパッケージをインストールすることができます。これは、システム全体でnumpyをインストールしたいが、numpyに依存する異なるパッケージを素早く繰り返したい場合に便利です。 @mona-jalalあなたのアップデートでは、仮想環境の作成方法はまだ表示されません。しかし、@ HaraldNordgrenの提案はうまくいくはずです。しかし、最初にsudoを試してみたので、使用しているファイルがもう書き換えられないことがあるので、新しい環境(cv3かもしれない)を作って試してみることをお勧めします。 – gunan

1

pipsudoとvirtualenvから実行しているという問題があります。これにより一時的にrootになり、virtualenvwrapperによって設定されたすべての環境変数がリセットされ、virtualenvではなくシステム全体にパッケージがインストールされます。

これは、より良い動作するはず:

workon cv2 
pip install keras tensorflow