PyCharm 5.0.1 doesn't resolve builtin modules

2019-04-11 16:04发布

My PyCharm 5.0.1 installation does not resolve references to any builtin modules or methods:

enter image description here

As you can see, I have installed python over cygwin.

I already tried:

  • reinstalling / updating the python installation (from 2.7.9 to 2.7.10)
  • reinstalling pycharm
  • adding a interpreter path to the python-skeletons in the pycharm installation directory (this was immediately removed by the ide when saving the settings, implying, that it already is embedded)
  • removing the interpreter (this removes the warnings, but also the code completion, and import asdflkjasd is valid as well)
  • adding various paths like /lib/python2.7/site-packages/ to the interpreter packages option

None of these improved the situation. How can I fix this without installation outside of cygwin alltogether?

2条回答
一夜七次
2楼-- · 2019-04-11 16:40

This is an update with a much better solution than my previous answer (which I completely missed that OP was asking for a solution that didn't require exactly what I suggested).

Like Carl commented above, updating python-skeletons is actually the way to go, however, if you're using Cygwin, the interpreter paths are a little wonky, and PyCharm won't always automatically add the right paths. For me, PyCharm handled it just fine in version 4.5.4, but not 5.0.4.

You'll find the python builtins in your Pycharm config directory, probably at:

C:\Users\[USERNAME]\.PyCharm50\system\python_stubs\-[RANDOM_STRING_OF_NUMBERS]

Just manually add this path (or paths) to your interpreter and it should resolve your problem. You can do the same for your site-packages folder if that's currently polluting your project structure space.

To get to the right menu:

  1. Click File -> Settings
  2. Navigate to Project -> Project Interpreter
  3. Click the gear on the top right and click "More"
  4. Select your interpreter and click the "Show paths" button on the right
  5. Instead of clicking refresh, as many other posts suggest, click the "Add" button on the right and add your paths

There's a handy screenshot uploaded by r---------k on the updating python-skeletons post that if that helps you.

Try installing the Python package for Windows from http://www.python.org/download/windows and point PyCharm to that interpreter instead.

Settings -> Project -> Project Interpreter -> Gear -> Add Local

You may also need to install PyCharm's Python packaging tools (you should see a link on the bottom of the Project Interpreter page if it isn't installed already).

While this may not be a perfect solution depending on your workflow because PyCharm will no longer be using Cygwin's python interpreter, but this at least got rid of those pesky squiggly red underlines for me.

查看更多
再贱就再见
3楼-- · 2019-04-11 16:49

I use Windows 10 x64, Python 3.5.1 and PyCharm Community Edition 2016.1.4

I have the same problem and sovled it by runnig PyCharm in admin mode (it is required only once).

查看更多
登录 后发表回答