【问题标题】:how to run jupyter with virtualenv in mac如何在 mac 中使用 virtualenv 运行 jupyter
【发布时间】: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


    【解决方案1】:

    在解决这个问题大约一个小时后,它突然开始自行工作。 macos 可能在内部尝试定位和链接其库,这需要一些时间。

    现在当我执行“help('modules')”时,它会在列表中包含 keras。

    【讨论】:

      猜你喜欢
      • 2020-04-25
      • 2018-08-13
      • 2020-07-19
      • 1970-01-01
      • 2013-08-27
      • 2021-03-25
      • 1970-01-01
      • 2017-07-15
      • 2011-01-22
      相关资源
      最近更新 更多