2

I have new Anaconda and PyCharm installations on Windows machine.

Simply running

import numpy

raises

ImportError: DLL load failed: The specified module could not be found.

In similar questions (1, 2), people suggest to check that PATH has paths to DLLs. In my case - it does! But instead, I have additional paths prepended to PATH when I start something from PyCharm. And I think this could be the problem.

When running from Anaconda prompt, sys.path is:

C:\Users\usr\Anaconda3\python37.zip
C:\Users\usr\Anaconda3\DLLs
C:\Users\usr\Anaconda3\lib
C:\Users\usr\Anaconda3
C:\Users\usr\Anaconda3\lib\site-packages
C:\Users\usr\Anaconda3\lib\site-packages\win32
C:\Users\usr\Anaconda3\lib\site-packages\win32\lib
C:\Users\usr\Anaconda3\lib\site-packages\Pythonwin

When running from python console in Pycharm, sys.path is the same, except that now we have two addional lines in the beginning of the file:

C:\Users\usr\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\182.4505.26\helpers\pydev
C:\Users\usr\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\182.4505.26\helpers\pydev

By the way, the initial error is raised from C:\Users\usr\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\182.4505.26\helpers\pydev\_pydev_bundle\pydev_import_hook.py.
So I think this locates the problem, yet I don't know why it arises, why it didn't happen on my other machine, and more importantly, how to fix it?


Technical data:

PyCharm 2018.2.4 (Community Edition)
Build #PC-182.4505.26, built on September 19, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Windows 10 10.0

Python: 3.7, 3.6.6;

numpy: 1.15.4; 1.14.6
icemtel
  • 412
  • 5
  • 12

2 Answers2

2

It is an open bug; This answer from Jetbrains issue tracker temporarily fixed the problem for me.

  • open command line
  • activate conda venv
  • get the correct PATH value by echo %PATH%
  • open PyCharm and set new PATH value
    • for Python console in Settings | Build, Execution, Deployment | Console | Python Console | Environment variables
    • for running scripts in Run | Edit Configurations ... | | Environment variables

UPD: The bug fixed in 2019.1

icemtel
  • 412
  • 5
  • 12
0

Last I found from pydev is this workaround, which is like pycharm but from within eclipse IDE as a plugin:

"As a note, right now the workaround can be starting Eclipse from that shell, going to the related interpreter and adding a 'PATH' environment variable to match the one which is expected to run conda (you can force environment variables for a specific interpreter)." Link

This probably can be done the same way for pycharm, ie. launching pycharm from within the correct environment, and explicitly setting the path variable as well.