9

我在 Mac OSX Lion 机器上,我已经下载了 wxPython-src-2.9.3.1.tar.bz2。然后我做了以下事情(注意:输出消息已被删除):

$ tar -xjf wxPython-src-2.9.3.1.tar.bz2
$ cd wxPython-src-2.9.3.1
$ mkdir bld
$ cd bld
$ source /path/to/myvirtualenv/bin/activate
(myvirtualenv)$ cross_compiling=yes
(myvirtualenv)$ export MACOSX_DEPLOYMENT_TARGET=10.6.7
(myvirtualenv)$ set arch_flags="-arch ppc64 "
(myvirtualenv)$ ../configure \
--with-mac --enable-monolithic --enable-threads --enable-unicode \
--enable-debug_flag --enable-debug \
--with-libpng --with-libjpeg --with-libtiff --enable-unicode \
--with-opengl --enable-graphics_ctx --with-odbc --enable-gui \
--with-macosx-sdk=/Developer/SDKs/MacOSX10.6.sdk --with-macosx-version-min=10.6 \
CFLAGS="$arch_flags" CXXFLAGS="$arch_flags" CPPFLAGS="$arch_flags" LDFLAGS="$arch_flags" OBJCFLAGS="$arch_flags" OBJCXXFLAGS="$arch_flags" --prefix=/path/to/myvirtualenv/
$ (myvirtualenv)make
$ (myvirtualenv)make install

之后,我确实收到了这条消息(所以我猜它成功了):

...
 ------------------------------------------------------

 The installation of wxWidgets is finished.  On certain
 platforms (e.g. Linux) you'll now have to run ldconfig
 if you installed a shared library and also modify the
 LD_LIBRARY_PATH (or equivalent) environment variable.

 wxWidgets comes with no guarantees and doesn't claim
 to be suitable for any purpose.

 Read the wxWindows Licence on licencing conditions.

 ------------------------------------------------------

让我回到我的壳里。但是,我似乎无法使用它

(myvirtualenv)$ python
>>> import wxversion
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named wxversion

有什么想法可以将它安装在我的 virtualenv 中吗?

4

6 回答 6

8

对于其他人,这对我有用:

在 Mac OSX 上,我使用 Homebrew 安装了 wxpython:

brew install wxpython

切换到您的 virtualenv 站点包目录:

cd /venv/lib/python2.7/site-packages

然后链接 wx.pth

ln -s /usr/local/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx.pth wx.pth

然后链接 wx-3.0-osx_cocoa 目录:

ln -s /usr/local/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-3.0-osx_cocoa wx-3.0-osx_cocoa
于 2014-12-12T02:51:25.933 回答
3

看完以上所有文章,这才是真正的关键:

您需要将您的 VE 指向主要的 python 安装。

在我的系统上:

% ln /Library/Python/2.7/site-packages/wxredirect.pth ./default/lib/python2.7/site-packages/wxredirect.pth

于 2013-08-15T14:24:25.323 回答
2

For Windows, you can use the same approach that cweston outlined for OS X, translated to calls to mklink. I had success creating a virtualenv for an old Python 2.7 / WxPython 2.8 based app by doing the following:

Install WxPython using the installer.

Find the site-packages directory where WxPython was installed. For me,

C:\Python27\Lib\site-packages

Open a shell and change to the site-packages directory inside the virtualenv to which you want to add WxPython, say it's called WxApp:

cmd
cd C:\Virtualenvs\WxApp\Lib\site-packages

Then create links: hard links for wx.pth and wxversion.py, and a junction for the directory containing the WxPython installation (mine was wx-2.8-msw-unicode):

mklink /h wx.pth C:\Python27\Lib\site-packages\wx.pth
mklink /h wxversion.py C:\Python27\Lib\site-packages\wxversion.py
mklink /j wx-2.8-msw-unicode C:\Python27\Lib\site-packages\wx-2.8-msw-unicode\

Now I have access to the wx module:

C:\> C:\VirtualEnvs\WxApp\scripts\activate.bat
(WxApp) C:\>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'2.8.12.1 (msw-unicode)'
>>>
于 2015-01-22T22:16:13.570 回答
0

我写了一个小脚本来为我的项目解决这个问题。觉得分享一下可能不错。

我有以下设置:

  • 通过 home-brew 安装的 python 和 wxpython
  • 使用 virtualenvwrapper 管理虚拟环境

使用 mkproject 启动新项目后,我运行以下脚本来解决此问题。

#!/usr/bin/env bash

echo This script fixes issues with wxpython and virtualenv on mac os. >&2
echo It needs to be run inside a virtualenv created with virtualenvwrapper. >&2
echo It also assumes that wxpython was installed through homebrew. >&2
echo

PYTHON_FULL_VERSION=$(python --version 2>&1 | awk -F ' ' '{ print $2 }')
PYTHON_SHORT_VERSION=$(python -c 'import sys; print "%d.%d" % (sys.version_info[0], sys.version_info[1])')

echo detected python version: "$PYTHON_FULL_VERSION" >&2

[ -d "$VIRTUAL_ENV" ] || { echo "ERROR: First activate the virtualenvironment." >&2; exit 1; }

# PART 1: Add homebrew-installed wx to env's site-packages
HOMEBREW_SITE_PKG="/usr/local/lib/python${PYTHON_SHORT_VERSION}/site-packages"
VENV_SITE_PKG="${VIRTUAL_ENV}/lib/python${PYTHON_SHORT_VERSION}/site-packages"

ln -s "${HOMEBREW_SITE_PKG}/wx.pth" "$VENV_SITE_PKG"
ln -s "${HOMEBREW_SITE_PKG}/wx-3.0-osx_cocoa" "$VENV_SITE_PKG"

# PART 2: At activation of venv we set PYTHONHOME
# NB This needs virtualenvwrapper to work
echo 'export PYTHONHOME="$VIRTUAL_ENV"' >> "${VIRTUAL_ENV}/bin/postactivate"

# PART 3: link the pythonw executable in the virtualenv
PYTHONW="/usr/local/Cellar/python/${PYTHON_FULL_VERSION}/bin/pythonw"
ln -s "$PYTHONW" "${VIRTUAL_ENV}/bin/pythonw"

echo "You should now re-activate the environment."
于 2014-12-22T12:34:03.813 回答
0

那是因为当你安装你的 python 版本时,你必须要求CPython安装是用--enable-framework. 因此,在您的 Mac 上,您必须运行以下命令:

$ env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.x.x
于 2017-10-05T16:53:34.257 回答
0

我相信最干净的方法是让您的系统 python 从您的开发工作中尽可能干净。您在其中添加的随机内容越多,您就越有可能遇到一些晦涩的问题。

因为它是系统范围的 brew 安装,这是 wxPython 最简单的选择,由于某种原因,它似乎没有正确的 python 打包/pip 集成。在这种情况下,它将进入您的系统范围的站点包。

virtualenv 支持以只读方式将系统范围的站点包链接到您的 virtualenv。确保使用--system-site-packages开关创建 virtualenv。这将使其对底层 python 安装透明。

我希望这可以帮助人们在未来遇到这个问题。

于 2016-06-09T07:12:10.923 回答