简体   繁体   English

Conda vtk 已安装,但 python 显示 - 没有名为 vtk 的模块

[英]Conda vtk is already installed but python shows - No module named vtk

I am trying to install vtk for python 2.7 for Windows 64 bit PC我正在尝试为 Windows 64 位 PC 的 python 2.7 安装 vtk

C:\Users\Abhi>conda install vtk
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

Where as然而

C:\Users\Abhi>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named vtk
>>>

for pip also I've tried对于 pip 我也试过

C:\Users\Abhi>pip install vtk
Collecting vtk

ERROR: Could not find a version that satisfies the requirement vtk错误:找不到满足 vtk 要求的版本

(from versions: none) ERROR: No matching distribution found for vtk (来自版本:无)错误:没有为 vtk 找到匹配的发行版

I've tried installing from executable file https://vtk.org/download/我试过从可执行文件https://vtk.org/download/安装

Any help would be appreciated任何帮助,将不胜感激

Thanks Abhishek谢谢阿布舍克

It sounds like you may be installing VTK for a python environment, but then using another one when you try importing it.听起来您可能正在为 python 环境安装 VTK,但是当您尝试导入它时使用另一个。 It's important to keep track of which python you are using when performing an install.在执行安装时,跟踪您使用的 python 非常重要。

The way I keep things organized is to create conda environments.我让事情井井有条的方式是创建 conda 环境。 If I were you, I would do the following:如果我是你,我会做以下事情:

Create a conda environment (you can specify any version of python you want)创建一个conda环境(你可以指定你想要的任何版本的python)

conda create -n myenv python=3.4

Now, you've created an environment in which you can install packages for your own python project.现在,您已经创建了一个环境,您可以在其中为您自己的 python 项目安装包。 You can create other environments with different packages and versions for other python projects using this command.您可以使用此命令为其他 python 项目创建具有不同包和版本的其他环境。 Next, make sure to activate your conda environment (you must do this every time you start a new session)接下来,确保激活您的 conda 环境(每次开始新会话时都必须这样做)

conda activate myenv

Now, after activating your environment, make sure that your environment is indeed active by running现在,在激活您的环境后,通过运行确保您的环境确实处于活动状态

conda info --envs

The active environment will have a * next to it.活动环境旁边会有一个 *。 Make sure that the * is next to "myenv", not base.确保 * 在“myenv”旁边,而不是 base。

After making sure you are indeed in your active environment, install all packages you need (including VTK).在确保您确实处于活动环境中之后,安装您需要的所有软件包(包括 VTK)。 Here's how to install vtk:下面是安装vtk的方法:

conda install -c anaconda vtk 

After you're done installing packages, you can make sure they are installed in your environment by running安装完软件包后,您可以通过运行确保它们已安装在您的环境中

conda list

Scroll down until you see your package.向下滚动,直到看到 package。

Now, you should be able to run python scripts with the packages you installed.现在,您应该能够使用您安装的包运行 python 脚本。 Test things out by running your import vtk line and let us know if things worked.通过运行你的 import vtk 线来测试一下,如果一切正常,请告诉我们。

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

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