简体   繁体   English

在python虚拟环境中访问包

[英]Accessing package in python virtual environment

I have a virtual environment in which I have installed 'geopandas'.我有一个安装了“geopandas”的虚拟环境。 When I do a pip list it lists this package as well.当我做一个 pip list 时,它也会列出这个包。 But when I try to call it in my jupyter notebook via 'import geopandas' I get a ModuleNotFoundError.但是当我尝试通过“导入 geopandas”在我的 jupyter 笔记本中调用它时,我得到了一个 ModuleNotFoundError。 Please help - I'm using windows machine请帮忙 - 我正在使用 Windows 机器

You can verify that your notebook is running in the correct virtual environment by doing:您可以通过执行以下操作来验证您的笔记本是否在正确的虚拟环境中运行:

import sys
sys.version

Here's how to run a Jupyter notebook in a virtualenv. 这是在 virtualenv 中运行 Jupyter notebook 的方法。

You should check if your notebook is using the correct kernel (the correct virtualenv).您应该检查您的笔记本是否使用了正确的内核(正确的 virtualenv)。 If you are still in the kernel using your standard environment and geopandas is not installed, it is possible you get this error.如果您仍在使用标准环境的内核中并且未安装geopandas ,则可能会出现此错误。

So check if you are working in the correct kernel: kernel check所以检查你是否在正确的内核中工作:内核检查

You can install a kernel in jupyter notebook by activating the venv and then installing it:您可以通过激活 venv 然后在 jupyter notebook 中安装内核:

source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

More info about this install here .有关此安装的更多信息请点击此处

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

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