2
votes

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.

2
if you have a script to run try running from the command line. Type 'python your_filename.py' and hit return on the command line. If it runs type 'which python' to determine which version of python you ran. If these all work then it seems that your problem is with Pycharm. Either how you installed it or how you ran it. If first commands don't work it most likely a python issue on your machine.Natsfan
Thanks for the update. I already tried out all the above but it doesn't seem to work. I don't have Python issues I am sure about that because Anaconda and all run properly. I am using Spyder currently and there the Python console works. Installation and running PyCharm is a no brainer (simple click to install like Windows) so I am sure the problem is with PyCharmenigma6174
Since you installed Anaconda and Spyder have you tried using virtual environments which are nicely described in the Anaconda documentation? The may be described well in Pycharm too and they may be required by PyCharm if more than 1 version of python is installed. Running PyCharm may be a no brainer but any python executable could be confused if multiple pythons are installed and virtual environments are NOT used. It takes two lines and a few minutes to install virtual environments for python 2.7 and 3.6.Natsfan
Sorry for the late reply but I tried your solutions none of them worked, maybe (and mostly I guess it's an issue of PyCharm for eg. similar to Netbeans 8.2 not working with jdk 9 and above) so now I am using Spyder. Thanks for the help though!enigma6174
@jmh figured out the solution and posted an answer here, but I still couldn't figure out what was causing the problem. My best guess would be SIP which is enabled by default for Macenigma6174

2 Answers

0
votes

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 :
    Screenshot of hosts configuration file 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 : Screenshot of file sharing screen
    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.

P.S.
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).

0
votes

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

127.0.0.1 localhost