[英]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. 我目前正在使用Mac OS Sierra和PyCharm Ultimate Edition的最新(更新)版本。 However, every time I try to run the Python console, it fails. 但是,每次我尝试运行Python控制台时,它都会失败。
I have tried multiple solutions which include the following: 我尝试了多种解决方案,其中包括:
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. 初始化 socketserver.TCPServer中的文件“ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xmlrpc/server.py”,第598行。 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. init的init (自身,addr,requestHandler,bind_and_activate)文件“ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py”,第453行, init self.server_bind()文件“ / Library /frameworks/Python.framework/Versions/3.6/lib/python3.6/socketserver.py“,第467行,位于server_bind self.socket.bind(self.server_address)socket.gaierror中:[Errno 8]节点名或服务名,或未知无法连接到控制台进程。 Process finished with exit code 137 (interrupted by signal 9: SIGKILL) 退出代码为137的过程结束(被信号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 解
Navigate to /etc folder and open the hosts file for editing using the following command: 导航到/ etc文件夹,然后使用以下命令打开hosts文件进行编辑:
sudo vim hosts sudo vim主机
Ensure the hosts file looks as follows : 确保hosts文件如下所示:
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. 我所做的是注释掉了最后一行代码,并添加了新行127.0.0.1 my_computer_name ,这几乎解决了问题。
To get my_computer_name (in this example Anishs-MacBook-Pro.local ) you need to type the following in your terminal : 要获取my_computer_name (在此示例中为Anishs-MacBook-Pro.local ),您需要在终端中键入以下内容:
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 . 现在,您应该可以从Mac OS Sierra上的PyCharm本身访问交互式Python控制台,它的工作原理就像一个魅力 。
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. 此解决方案已在基于系统的python编译器和PyCharm的虚拟环境设置(都在项目创建向导中显示)上进行了测试,因此,无论您使用什么配置,都应该很好。
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). 另外,我只在Mac OS Sierra上尝试过此操作,因此我不确定它是否可以在Mac OS High Sierra或其他旧版本上使用(尽管经过大量的在线研究之后,我得出的结论是,该问题是特定于Mac OS Sierra)。
Please ensure that you added the localhost among your local in /etc/hosts
file; 请确保您在/etc/hosts
文件中的本地计算机中添加了本地/etc/hosts
; this worked for me: 这为我工作:
127.0.0.1 localhost
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.