Pycharm import error for VTK module, with anaconda

Hi,

I'm using the community edition of Pycharm.

PyCharm 2019.1.3 (Community Edition)
Build #PC-191.7479.30, built on May 29, 2019
JRE: 11.0.2+9-b159.60 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

I have setup an python interpreter, using conda, and installed VTK.

I use python 2.7 and VTK 7.1.1.

I ran this script through PyCharm and the windows console.

import sys
import os
import pkg_resources
from pprint import pprint


pprint({
'sys.version_info': sys.version_info,
'sys.prefix': sys.prefix,
'sys.path': sys.path,
'pkg_resources.working_set': list(pkg_resources.working_set),
'PATH': os.environ['PATH'].split(os.pathsep),
})

import vtk

It runs correctly with the external console but not with Pycharm which fails with the error ImportError: No module named vtkRenderingFreeTypePython.

Here is the output on both environments.

Console:

{'PATH': ['C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\Library\\bin',
'C:\\Program Files\\ImageMagick-7.0.8-Q16',
'C:\\ProgramData\\Oracle\\Java\\javapath',
'C:\\WINDOWS\\system32',
'C:\\WINDOWS',
'C:\\WINDOWS\\System32\\Wbem',
'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Program Files\\Microsoft\\Web Platform Installer\\',
'C:\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET Web Pages\\v1.0\\',
'C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\',
'C:\\Program Files\\dotnet\\',
'C:\\WINDOWS\\system32\\config\\systemprofile\\.dnx\\bin',
'C:\\Program Files\\Microsoft DNX\\Dnvm\\',
'C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\',
'C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\',
'C:\\Program Files\\Common Files\\Autodesk Shared\\',
'C:\\Program Files (x86)\\Autodesk\\Backburner\\',
'C:\\Users\\lmainguy\\AppData\\Local\\Microsoft\\WindowsApps',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition 2019.1.3\\bin',
''],
'pkg_resources.working_set': [wsgiref 0.1.2 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib),
wincertstore 0.2 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
wheel 0.33.4 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
setuptools 41.0.1 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
pip 19.1.1 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
future 0.17.1 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
certifi 2019.3.9 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages)],
'sys.path': ['C:\\Users\\lmainguy\\PycharmProjects\\Test',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\python27.zip',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\DLLs',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib\\plat-win',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib\\lib-tk',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib\\site-packages'],
'sys.prefix': 'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test',
'sys.version_info': sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0)}

Pycharm:

{'PATH': ['C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\Library\\mingw-w64\\bin',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\Library\\usr\\bin',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\Library\\bin',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\Scripts',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\bin',
'C:\\Program Files\\ImageMagick-7.0.8-Q16',
'C:\\ProgramData\\Oracle\\Java\\javapath',
'C:\\WINDOWS\\system32',
'C:\\WINDOWS',
'C:\\WINDOWS\\System32\\Wbem',
'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Program Files\\Microsoft\\Web Platform Installer\\',
'C:\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET Web Pages\\v1.0\\',
'C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\',
'C:\\Program Files\\dotnet\\',
'C:\\WINDOWS\\system32\\config\\systemprofile\\.dnx\\bin',
'C:\\Program Files\\Microsoft DNX\\Dnvm\\',
'C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\',
'C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\',
'C:\\Program Files\\Common Files\\Autodesk Shared\\',
'C:\\Program Files (x86)\\Autodesk\\Backburner\\',
'C:\\Users\\lmainguy\\AppData\\Local\\Microsoft\\WindowsApps',
'C:\\Program Files\\JetBrains\\PyCharm Community Edition 2019.1.3\\bin',
''],
'pkg_resources.working_set': [wsgiref 0.1.2 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib),
wincertstore 0.2 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
wheel 0.33.4 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
setuptools 41.0.1 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
pip 19.1.1 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
future 0.17.1 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages),
certifi 2019.3.9 (c:\users\lmainguy\appdata\local\continuum\anaconda2\envs\test\lib\site-packages)],
'sys.path': ['C:\\Users\\lmainguy\\PycharmProjects\\Test',
'C:\\Users\\lmainguy\\PycharmProjects\\Test',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\python27.zip',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\DLLs',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib\\plat-win',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib\\lib-tk',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test',
'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test\\lib\\site-packages'],
'sys.prefix': 'C:\\Users\\lmainguy\\AppData\\Local\\Continuum\\anaconda2\\envs\\Test',
'sys.version_info': sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0)}
Traceback (most recent call last):
File "C:/Users/lmainguy/PycharmProjects/Test/TestImport.py", line 23, in <module>
import vtk
File "C:\Users\lmainguy\AppData\Local\Continuum\anaconda2\envs\Test\lib\site-packages\vtk\__init__.py", line 60, in <module>
from .vtkRenderingFreeType import *
File "C:\Users\lmainguy\AppData\Local\Continuum\anaconda2\envs\Test\lib\site-packages\vtk\vtkRenderingFreeType.py", line 9, in <module>
from vtkRenderingFreeTypePython import *
ImportError: No module named vtkRenderingFreeTypePython

It looks like a bug on Pycharm but maybe I missed something while configuring my environment.

Thanks for your help,

Ludovic

5 comments
Comment actions Permalink

Please try to run PyCharm from the terminal with activated conda environment, using `<pycharm_install_path>/bin/pycharm.bat` file.

0
Comment actions Permalink

Hmmm it seems there is a bug with the script.

The vm options file is not found by the script.

I have installed the x64 version of PyCharm.

But the script fails to acknowledge that.

It relies on the existence on a folder <root_path>\jre64\lib\amd64 to detect whether or not Pycharm is running on x64 platform.

IF EXIST "%JRE%\lib\amd64" SET BITS=64

But this folder is not there which causes the script to miss the vm options file later on.

  :: default, standard installation
SET VM_OPTIONS_FILE=%IDE_BIN_DIR%pycharm%BITS%.exe.vmoptions

 

0
Comment actions Permalink

Did you install it from JetBrains official site? https://www.jetbrains.com/pycharm/download/#section=windows

There is no 64-bit version of PyCharm, there is only 64-bit JDK which PyCharm runs on. I also have 64-bit JDK and don't have "<root_path>\jre64\lib\amd64" folder, but pycharm.bat start PyCharm without issues for me.

I've tried to reproduce the issue, but could not. First, there doesn't seem to be vkt=7.1.1 in standard Conda repository, so I installed 6.3.0 which is default. Then I pasted your code snippet and it runs fine for me.

I'm a little concerned about `anaconda2` in your path. Do you have multiple anaconda installations?

0
Comment actions Permalink

Yes, I downloaded it from Jetbrains official site.

Anaconda2 just means it uses Python 2.7. I currently the 2018.12 64 bits version of Anaconda.

 

I have a pycharm64.exe and a pycharm64.exe.vmoptions in my bin folder.

Pycharm64.exe is indeed a 64 bits executable, as confirmed by dumpbin

Dump of file C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.3\bin\pycharm64.exe
PE signature found
File Type: EXECUTABLE IMAGE
FILE HEADER VALUES
8664 machine (x64)

If I force BITS to 64, the script runs correctly and PyCharm opens.

It seems to indicate a bug in the script at least at 2019.1.3 version.

That said, if I run Pycharm through the anaconda command prompt, VTK import are properly resolved and my program starts.

So I guess that's an acceptable workaround though it would be great if PyCharm would take care to activate the conda environment for me at program start.

0
Comment actions Permalink

>it would be great if PyCharm would take care to activate the conda environment for me at program start

It should though, see https://youtrack.jetbrains.com/issue/PY-35141

We'll continue to gather more feedbacks and data, but if you can reproduce the issue and provide the steps, that would help.

0

Please sign in to leave a comment.