Pycharm does not use PATH settings for conda environment
I am having some troubles using PyCharm after some recent updates (exactly which ones I am no longer sure), that all involve the system PATH (not the PYTHONPATH). I am running on Windows, with a fresh install of Anaconda 2021.05 as a local install (just for me) - although, I am operating a conda environment with just a subset of packages installed.
It started when suddenly I could not import numpy due to a DLL import error. According to my searches on the internet, I had to add the Library\bin folder from my Anaconda3 installation to my PATH variable (which worked, but I've never had to do before). I have left that there, even though I don't like it, but then I started having problems with similar things with other packages. Everything works with no issues at all if it is run from an Anaconda command prompt (not involving PyCharm). But running scratches that way (for example) is really really frustrating.
Here is what I get when I examine the PATH in the aforementioned command prompt when the py_utils environment is active:
(py_utils) C:\>for %a in ("%path:;=";"%") do @echo %~a
C:\Users\asmith\Anaconda3\envs\py_utils
C:\Users\asmith\Anaconda3\envs\py_utils\Library\mingw-w64\bin
C:\Users\asmith\Anaconda3\envs\py_utils\Library\usr\bin
C:\Users\asmith\Anaconda3\envs\py_utils\Library\bin
C:\Users\asmith\Anaconda3\envs\py_utils\Scripts
C:\Users\asmith\Anaconda3\envs\py_utils\bin
C:\Users\asmith\Anaconda3\condabin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\libnvvp
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Windows\CCM
C:\Windows\CCM
C:\Windows\CCM
C:\Windows\CCM
C:\Windows\CCM
C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit
C:\Program Files\Microsoft SQL Server\110\Tools\Binn
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0
C:\Program Files\Microsoft SQL Server\120\Tools\Binn
C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn
C:\Program Files\TortoiseHg
C:\Program Files\TortoiseSVN\bin
C:\Program Files\TortoiseGit\bin
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Users\asmith\AppData\Local\Microsoft\WindowsApps
C:\Users\asmith\AppData\Local\LyX 2.3\Perl\bin
C:\Users\asmith\AppData\Local\Programs\Git\mingw64\bin
C:\Users\asmith\MinGW\bin
C:\Users\asmith\Documents\PortablePrograms\CMake\bin
C:\Users\asmith\AppData\Local\Programs\Microsoft VS Code\bin
C:\Users\asmith\Anaconda3\Library\bin
C:\Users\asmith\AppData\Local\Programs\MiKTeX\miktex\bin\x64
The block at the bottom contains my local environment settings for PATH - the block at the top is clearly the Anaconda prompt adding its set of directories to the PATH.
I have a python_utils project in PyCharm, for which I am using the py_utils conda environment. But when I examine the PATH in a Python console, this is all I get:
In[2]: import os
In[3]: os.getenv('PATH').split(';')
Out[3]:
['C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.1\\bin',
'C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v9.1\\libnvvp',
'C:\\Windows\\system32',
'C:\\Windows',
'C:\\Windows\\System32\\Wbem',
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Windows\\CCM',
'C:\\Windows\\CCM',
'C:\\Windows\\CCM',
'C:\\Windows\\CCM',
'C:\\Windows\\CCM',
'C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\',
'C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\',
'C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\',
'C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\',
'C:\\Program Files (x86)\\Microsoft SQL Server\\90\\Tools\\binn\\',
'C:\\Program Files\\TortoiseHg\\',
'C:\\Program Files\\TortoiseSVN\\bin',
'C:\\Program Files\\TortoiseGit\\bin',
'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common',
'C:\\Users\\asmith\\AppData\\Local\\Microsoft\\WindowsApps',
'C:\\Users\\asmith\\AppData\\Local\\LyX 2.3\\Perl\\bin',
'C:\\Users\\asmith\\AppData\\Local\\Programs\\Git\\mingw64\\bin',
'C:\\Users\\asmith\\MinGW\\bin',
'C:\\Users\\asmith\\Documents\\PortablePrograms\\CMake\\bin',
'C:\\Users\\asmith\\AppData\\Local\\Programs\\Microsoft VS Code\\bin',
'C:\\Users\\asmith\\Anaconda3\\Library\\bin',
'C:\\Users\\asmith\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64']
Notice that the whole block at the top with C:\Users\asmith\Anaconda3\envs\py_utils is missing, and a whole host of things apparently need that to be there (numpy, pyqt, cartopy). Note that the PYTHONPATH settings for the environment work just fine ... I get OSErrors related to DLLs, not ModuleNotFound errors.
I very very much do NOT want to have Anaconda permanently in my PATH. I have diligently searched but I too often find people's issues with the PYTHONPATH, not the system PATH. The closest thing I have found is this unanswered post: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000643679-Use-environment-variables-from-conda-environment?input_string=Pycharm%20system%20PATH%20does%20use%20conda%20environment
I used to not have any problems with this. What changed to make PyCharm not find the appropriate PATH so that DLLs can be found? How do I fix this?
请先登录再写评论。
Has this been solved?