简体   繁体   中英

Python console not working in PyCharm running on Mac OS

I am currently using Mac OS Sierra and the latest (updated) version on PyCharm ultimate edition. However, every time I try to run the Python console, it fails.
I have tried multiple solutions which include the following:

  • Try out the solutions mentioned in similar StackOverflow questions.
  • Remove Anaconda completely (restart system) and then try running the console.
  • Removed and re-installed PyCharm.
  • Use different version of Python (2.7/3/3.5/3.6)
  • Create a project in a virtual environment.
  • Delete the .idea directory in the project folder.

However, in after a lot of debugging I failed to correct the errors. Here's the output error :

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xmlrpc/server.py", line 598, in init socketserver.TCPServer. init (self, addr, requestHandler, bind_and_activate) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", line 453, in init self.server_bind() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py", line 467, in server_bind self.socket.bind(self.server_address) socket.gaierror: [Errno 8] nodename nor servname provided, or not known Couldn't connect to console process. Process finished with exit code 137 (interrupted by signal 9: SIGKILL)

Thus, if anyone knows how to fix this error, it would be of great help. Please feel free to ask for further information if I missed something.

SOLUTION

  • Download the latest version of PyCharm from here
    Note that this is the latest release of PyCharm which is I guess in beta development and hence might not be stable.
  • Navigate to /etc folder and open the hosts file for editing using the following command:

    sudo vim hosts

  • Ensure the hosts file looks as follows :
    主机配置文件的屏幕快照 What I have done is commented out the last line of code and added a new line 127.0.0.1 my_computer_name which almost solves the problem.

  • To get my_computer_name (in this example Anishs-MacBook-Pro.local ) you need to type the following in your terminal :

    hostname

  • Once you are done with all this, now comes the last step : open System Preferences > Sharing
    Once you have opened the Sharing window, ensure you have File Sharing option selected. If it is not selected, select it.

  • Give Read And Write access to every user to all shared folders under the shared folders tab. Here's a screenshot : 文件共享屏幕截图
    NOTE: I haven't given read and write access to staff user but for me it worked fine. But do ensure to give the read and write access to all the shared folders.

  • Once all this is done, restart your computer (not necessary, but better) and everything should be fine. You should now be able to access your interactive Python console from PyCharm itself on Mac OS Sierra and it works like a charm .

PS
This solution is tested on both system based python compiler and virtual environment setting of PyCharm (both of which are presented during project creation wizard) and hence should be fine no matter what configuration you are using.

Also, I have only tried this on Mac OS Sierra so I am not sure if it will work on Mac OS High Sierra or other older versions (though after quite a bit of extensive online research I came to the conclusion that this problem is particular to Mac OS Sierra).

Please ensure that you added the localhost among your local in /etc/hosts file; this worked for me:

127.0.0.1 localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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