简体   繁体   English

Python:没有名为Zlib的模块,Mac OS X El Capitan 10.11.6

[英]Python: No Module named Zlib, Mac OS X El Capitan 10.11.6

I'm trying to convert my python command line application to an app with py2app. 我正在尝试将我的python命令行应用程序转换为使用py2app的应用程序。 Everytime I try to import zlib or try to install setuptools , I get an error : no module named zlib. 每次我尝试导入zlib或尝试安装setuptools时,都会收到错误:没有名为zlib的模块。

Python was installed with brew. Python是用brew安装的。 I searched every corner of the internet and stack overflow, I have reinstalled python with brew , I have installed all Xcode CLI related stuff with : 我搜索了互联网的每个角落和堆栈溢出,我已经重新安装了使用brew的python,我已经安装了所有与Xcode CLI相关的东西:

xcode-select --install

I also ran : 我也跑了:

ls /usr/include/zlib.h

and I can see that zlib is there where it is supposed to be. 我可以看到zlib应该在那里。

Reinstalled with: 重新安装:

brew reinstall python

Unfortunately that didn't work for me. 不幸的是,这对我不起作用。 I can't get what is wrong. 我不知道有什么不对。

Any ideas? 有任何想法吗?

I had the same issue and the solution at https://github.com/Homebrew/homebrew-core/issues/29176 worked for me: re-install python@2 : 我有同样的问题, https//github.com/Homebrew/homebrew-core/issues/29176的解决方案对我python@2 :重新安装python@2

brew reinstall python@2

(Before I tried this I also tried installing zlib with Homebrew -- brew install zlib ; this may or may not have contributed to it working.) (在我尝试这个之前,我也尝试使用Homebrew安装zlib - brew install zlib ;这可能会也可能不会对它起作用。)

Solution from another answer worked for me. 另一个答案的解决方案对我有用。 It might be the issue with xcode install: https://stackoverflow.com/a/34996223/2792278 这可能是xcode安装的问题: https//stackoverflow.com/a/34996223/2792278

in terminal run 在终端运行中

xcode-select --install

and reinstall python with brew. 并使用brew重新安装python。

My solution on Mojave (10.14), simply by creating symbolic link. 我在Mojave(10.14)上的解决方案,只需创建符号链接即可。 Please take note your zlib and python version may vary. 请注意您的zlib和python版本可能会有所不同。

In terminal run the following:- 在终端运行以下: -

brew install zlib

ln -s /usr/local/Cellar/zlib/1.2.11/include/* /usr/local/include

ln -s /usr/local/Cellar/zlib/1.2.11/lib/* /usr/local/lib

brew reinstall python

Installing the MacOS SDK Headers as suggested by this issue solves this problem fairly cleanly. 按照此问题的建议安装MacOS SDK标头可以非常干净地解决这个问题。

To do so, run the following (for MacOS 10.14): 为此,请运行以下命令(对于MacOS 10.14):

xcode-select --install
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

and then brew install python 然后brew install python

Finally found the answer. 终于找到了答案。

After using: 使用后:

brew doctor

I found out that I had more config scripts in my path, according to brew doctor. 根据布鲁医生的说法,我发现我的路径中有更多的配置脚本。

So I did: 所以我做了:

sudo rm -rf /Library/Frameworks/Python.framework/

next : 下一个 :

brew prune

and finally: 最后:

brew install python

also had some linking problems so I ran: 还有一些链接问题,所以我运行:

 brew link python3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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