簡體   English   中英

PyCharm如何在macOS上創建與Matplotlib一起使用的virtualenv?

[英]How does PyCharm create a virtualenv that works with Matplotlib on macOS?

我使用通過Homebrew安裝的Python 3在macOS 10.14.3上,我已經用pip安裝了virtualenv

$ brew install python
$ pip3 install virtualenv

現在,以下問題已有詳細記錄,並且已知不起作用

$ virtualenv venv
$ source venv/bin/activate
$ pip install matplotlib ipython
$ ipython
In [1]: %matplotlib

ImportError: Python is not installed as a framework. The Mac OS X backend will
not be able to function correctly if Python is not installed as a framework.
See the Python documentation for more information on installing Python as a
framework on Mac OS X. Please either reinstall Python as a framework, or try
one of the other backends. If you are using (Ana)Conda please install
python.app and replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.

現在我注意到如果我使用“創建新項目”創建一個帶有PyCharm的virtualenv - “純Python”並將“Project Interpreter”設置為“使用Virtualenv的新環境”,我可以成功地將Matplotlib與任何已安裝的后端一起使用。 假設使用PyCharm創建的virtualenv駐留在文件夾venv2

$ source venv2/bin/activate
$ pip install matplotlib ipython
$ ipython
In [1]: %matplotlib
Using matplotlib backend: MacOSX

為什么這樣做? PyCharm如何創建virtualenv以便Matplotlib工作? 他們的文檔說他們也在使用virtualenv包,所以我不知道他們做了什么不同的事情。

請參閱https://matplotlib.org/faq/osx_framework.html

解決方案是不使用virtualenv,而是使用stdlib的venv,它提供類似的功能但沒有出現這個問題。

這是使用virtualenv命令創建的虛擬環境的錯誤。 PyCharm使用上面文檔中推薦的venv命令。

如果使用venv命令在終端中創建虛擬環境,它應該沒有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM