Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use wxPython in virtualenv?

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)

like image 302
tkbx Avatar asked Dec 11 '22 19:12

tkbx


2 Answers

(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!

like image 68
Anibalismo Avatar answered Dec 27 '22 11:12

Anibalismo


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
like image 27
cweston Avatar answered Dec 27 '22 10:12

cweston