【发布时间】:2019-07-30 09:07:24
【问题描述】:
我在mac中做了以下步骤,在终端和jupyter中运行python程序:
0. install python3 and virtualenv:
install python3.6.8 binary from python.org
sudo pip3 install virtualenv
which python3 # this is /usr/local/bin/python3
which pip3 # this is /usr/local/bin/pip3
which virtualenv # this is /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenv
1. create a virtualenv, with python3:
virtualenv -p /usr/local/bin/python3.6 keras
2. activate the virtualenv:
source keras/bin/activate
3. install keras and jupyter in the env:
(keras) pip3 install tensorflow keras jupyter
(keras) which python # this prints /Users/xxx/envs/keras/bin/python
(keras) which python3 # this prints /Users/xxx/envs/keras/bin/python3
(keras) which jupyter # this prints /Users/xxx/envs/keras/bin/jupyter
4. run from terminal:
(keras) python
>>> import sys
>>> print(sys.version) # this prints 3.6.8
>>> import keras
>>> print(keras.__version__) # this prints 2.2.4
>>> exit()
5. run from jupyter (in the same virtualenv, with safari browser):
(keras) jupyter notebook
import sys
print(sys.version) # prints 3.6.8
import keras # gives error, no module named 'keras'
但是在 ubuntu-18.04 中使用相同的代码,使用 chrome 浏览器。那么如何在mac中使用virtualenv运行jupyter,以便访问导入的模块呢?有没有我遗漏的步骤?
【问题讨论】:
标签: macos keras virtualenv