简体   繁体   English

python3.4中的虚拟环境不会导入不同的模块

[英]virtual environment in python3.4 won't import different modules

as a little disclaimer I'm completely new to both Linux/Terminal and Python, so excuse the imprecise terminology 作为一个小小的免责声明,我对Linux /终端和Python都是全新的,所以请原谅不精确的术语

I'm trying to follow the basic usage guide for the python-based scientific calculator PyPhi , a dedicated tool for calculated integrated information in a network. 我正在尝试遵循基于python的科学计算器PyPhi的基本使用指南, PyPhi是一种用于计算网络中集成信息的专用工具。 I've followed the installation guide , in which I brew installed the latest versions of python and python3 (2.7.9 and 3.4.2 at the time of writing), pip installed virtualenvwrapper, changed the ~/.bash_profile as suggested to 我按照安装指南 ,我在其中安装了最新版本的python和python3(编写时为2.7.9和3.4.2),pip安装了virtualenvwrapper,根据建议更改了〜/ .bash_profile

## Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
export PATH=/usr/local/bin:$PATH

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/dev
source /usr/local/bin/virtualenvwrapper.sh

and also installed numpy for both 2.7.9 and 3.4.2. 并且还为2.7.9和3.4.2安装了numpy。 When I create a virtual environment using the command 当我使用该命令创建虚拟环境时

mkvirtualenv -p `which python3` <name_of_your_project>

as suggested, I am able to import pyphi , but then attempting to import numpy as np brings up the error message 按照建议,我能够import pyphi ,但随后尝试import numpy as np会显示错误消息

 File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'

This doesn't happen when I run python3 without a virtual environment, as I can import both pyphi and numpy. 当我在没有虚拟环境的情况下运行python3时,这不会发生,因为我可以导入pyphi和numpy。 What's gone wrong with the virtualenvironment setup so that it doesn't work whilst in there? 虚拟环境设置出了什么问题,以至于它在那里不起作用?

Please refer this question , I think, you've got similar problem. 请参考这个问题 ,我想,你有类似的问题。 There are two ways: quick&dirty and proper. 有两种方法:快速,肮脏和正确。 Choose your own. 选择你自己的。

By the way, did you try adding Frameworks directory for 3.4.2 to $PATH ? 顺便说一句,您是否尝试将3.4.2的Frameworks目录添加到$PATH

PyPhi author here—it looks like you correctly created the virtual environment but didn't install the package while it was activated. PyPhi作者在这里 - 看起来你正确创建了虚拟环境但是在激活它时没有安装它。

Make sure the virtual environment is active by running workon <name_of_your_project before running pip install pyphi . 在运行pip install pyphi之前,通过运行workon <name_of_your_project确保虚拟环境处于活动状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM