I made a simple wxPython script that simply shows a window. When I run it in my normal python 2.7.3 with wxPython (import wx
), it works fine. But when I run it in a virtualenv, I get the following:
Traceback (most recent call last):
File "/Users/student/Desktop/text.py", line 3, in <module>
class mainWindow(wx.Frame):
AttributeError: 'module' object has no attribute 'Frame'
Why is this? I have wx installed (./pip install wx
in my virtualenv's bin folder)
(Im a python noob) I would coment here how I resolve to make wx work in a virtual env, tested on windows.
First you create your virtualenv (I did mine inside the project's directory)
virtualenv env
Then, go to the env\Lib\site-packages folder, and create a file there named wx.pth (name does not matter, only matters file extention)
Open the wx.pth file and edit it so it points to your wx-X.X-msw, where X.X is your wx version number. Mine is 3.0 (july 2014). it should be somethind like this:
C:\Python27\Lib\site-packages\wx-3.0-msw
activate your virtualenv. then open your python shell, and try running import wx; app = wx.App()
if you do not get any nasty messages, then you should be all set.
Hope this helps!
For others, here is what worked for me:
On Mac OSX I installed wxpython with Homebrew using:
brew install wxpython
Change into your virtualenv site-packages directory:
cd /venv/lib/python2.7/site-packages
then link the wx.pth
ln -s /usr/local/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx.pth wx.pth
and then link the wx-3.0-osx_cocoa directory:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With