Can't use wxPython in virtualenv?

I created a simple wxPython script that just shows a window. When I run it in my regular python 2.7.3 using wxPython ( import wx ), it works fine. But when I run it in 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 bin virtual folder)

+4
source share
5 answers

I, that these steps worked for me some time ago ...

wxpython in virtualenv

+2
source

(Im a python noob) I would like to write here how I decide to make wx work in a virtual env tested on windows.

First you create your virtualenv (I made it inside the project directory)

 virtualenv env 

Then go to the env \ Lib \ site-packages folder and create a file called wx.pth (the name does not matter, only the value of the file extension)

Open the wx.pth file and edit it to point to your wx-XX-msw, where XX is your wx version number. Mine - 3.0 (July 2014). it should be something 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() import wx; app = wx.App() , if you do not receive any unpleasant messages, then you must be configured.

Hope this helps!

+5
source

For others, here's what worked for me:

On Mac OSX, I installed wxpython using Homebrew using:

 brew install wxpython 

Go to the virtual sites directory:

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

then connect wx.pth

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

and then bind 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 
+3
source

wx in PyPI is a garbage module that has one trivial function. Unfortunately, someone got a name for their "first python module" in which many people are confused and annoyed .

The line you give import and pip install can obviously be different, for example. import PIL and pip install pillow , or almost every Django plugin. Here you want pip install wxpython

On Ubuntu, installing wxPython can be a little painful, so I would suggest installing it with apt-get install python-wxgtk2.8 , then (if your venv has --no-site-packages ), symbolizing the global library folder in virtualenv a folder la:

 nick@cody :~/sandbox/lib/python2.7/site-packages $ ls -lhtr wx* ... wx.pth -> /usr/lib/python2.7/dist-packages/wx.pth ... wx-2.8-gtk2-unicode -> /usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/ 
+2
source

This worked for me on windows virtualenv ...

Go here first to get the wxpython binary wheel codes that match your system http://www.lfd.uci.edu/~gohlke/pythonlibs/#wxpython

Now on the virtualenv command line, make sure you have the wheel

 >pip install wheel 

Then install wxpython common

 >pip install wxPython_common-3.0.2.0-py2-none-any.whl 

Finally install wxpython itself

 >pip install wxPython-3.0.2.0-cp27-none-win_amd64.whl 

Now in the python virtualenv interpreter, check if the installation was successful by creating and running the example

 >python ... >>> import wx >>> app = wx.App(False) >>> frame = wx.Frame(None, wx.ID_ANY, "Running from virtualenv!") >>> frame.Show(True) >>> app.MainLoop() 

If a window appears and no error occurs, then you're fine :)

+1
source

All Articles