Installing wxPython in virtualenv under Linux - linux

I am trying to set up a wxpython inside virtualenv.
As detailed in many places, the easy_install / pip install dosent work as setup.py is not present.
I cam across a description on how to set it up on a Mac, but found no such methods for Linux.
How can this be done on Linux ?
My actual use case is a little experimental. I am trying to get a django project call a wxpython app. This works outside of virtualenv, but the import fails as wx is not installed in virtualenv.
Thanks for the help in advance.

On Ubuntu 12.04 the following worked for me:
cd <env>/lib/python-2.7/site-packages
ln -s /usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/ .
ln -s /usr/lib/python2.7/dist-packages/wx.pth .
ln -s /usr/lib/python2.7/dist-packages/wxversion.py .
ln -s /usr/lib/python2.7/dist-packages/wxversion.pyc .

have you tried building it from source? it used to be a long process, but it looks like it's been improved recently. the instructions are at http://www.wxpython.org/builddoc.php and include the ability to specify an install directory. it builds fine on linux in my experience, once you have the dependencies installed.

Related

gobject-2.0-0 not able to load on macbook

I am facing this error when I start my flask application on Python3 and Mac OS:
OSError: cannot load library 'gobject-2.0-0': dlopen(gobject-2.0-0, 2): image not found. Additionally, ctypes.util.find_library() did not manage to locate a library called 'gobject-2.0-0'
I am using weasyprint in my project which is causing this issue.
I tried to install glib and it is installed in my system.
I just managed the same issue on my Mac M1.
The problem was that symlinks to the libraries were not created (can't say should it be done by homebrew or weasyprint when installation).
So, I had to do it manually
sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0
sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0
sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz
sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1
sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0
This solved the problem.
In order to TEST if Python can find the library you may run
from ctypes.util import find_library
find_library('gobject-2.0') # Pass any other lib name as an argument
UPD. There is no such problem if you install python with homebrew.
If you installed weasyprint package in your virtual env but did not installed some required packages for that, then that might be the reason. It was actually, in my case.
If you're mac user you need install pango and libffi, not to mention python as well.
Installation guide on mac
brew install python pango libffi
(venv) pip install weasyprint
To expand on the existing answers on Apple Silicon (M1) Macs:
If you have installed the packages with Homebrew and they are still not found or linked under /usr/local/lib, it is because they are installed on arm64 and found in /opt/homebrew/lib instead.
If you're using Python installed with Homebrew it should work without any extra work, however system Python and any managed Python versions (e.g. installed with Pyenv) will require some configuration.
1. Manual symlinking
Instead of linking each library individually to /usr/local/lib, you can link the /opt/homebrew/lib contents (as long as you don't have an existing /usr/local/lib directory):
sudo ln -s /opt/homebrew/lib /usr/local/lib
This will work as long as the library you're looking for is not from a keg-only formula (those will have to be linked individually).
2. Environment variables
A lot of answers point to setting some environment variable, like LDFLAGS or DYLD_LIBRARY_PATH to add search paths for libraries, but these will not work with Python based on my testing:
macOS comes with System Integrity Protection (SIP) which, among other things, sanitizes your environment variables in subprocesses, for example Python. Anything starting with LD or DYLD will be purged, so setting the environment variables in your terminal profile will not work.
You can Disable SIP to get these working, but Apple recommends only doing it temporarily when needed.
If you decide to go this route, here are a few options:
In Homebrew's Github discussions the question was answered by setting LDFLAGS:
export LDFLAGS=-L/opt/homebrew/lib
Similarly you could add the necessary paths to DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=/opt/homebrew/lib
I had the same issue after the homebrew update. Turned out the issue was because of the older pango lib version.
I did brew install pango
This upgraded pango lib from 1.48.2 -> 1.50.4 which internally installed gobject's latest version as dep. And my issue got resolved.

opengv installation not in pip3 list

I have a question. I followed the http://laurentkneip.github.io/opengv/
installation manual. And i did correct the path by using the command
cmake ../opengv -DBUILD_PYTHON=ON -DPYBIND11_PYTHON_VERSION=3.7 -DPYTHON_INSTALL_DIR=/usr/local/lib/python3.7/dist-packages/
and I also ran the command
sudo ln -s /usr/local/lib/python3.7/dist-packages/pyopengv.cpython-37m-x86_64-linux-gnu.so
to bring the built package in the opengv/build/lib to the python3-package....
But I really have no idea why!! There is no opengv in the pip3 list???
The final problem was that I can not import pyopengv in openSFM...
But the first problem is I think is because there is no opengv in pip3 list..

installed python 3x on mac but terminal still show version still 2x

I installed python 3x via home brew, the process was successful.
However when I check version, it shows 2x
here is the terminal output
➜ ~ brew install python
Warning: python 3.7.2 is already installed, it's just not linked
You can use `brew link python` to link this version.
➜ ~ brew link python
Linking /usr/local/Cellar/python/3.7.2... Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks
➜ ~ sudo brew link python
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
➜ ~ python -V
Python 2.7.10
I think I need to modify some kind of path. And do some magic then pray...lol
Anyway anyone know how to get this work on my machine? I'm mac latest
First, solve your permission problem by running the official command from the Homebrew Documentation, Troubleshooting page
cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Caskroom Frameworks
Then run brew link python
And finally run echo $PATH and check that your /usr/local/bin has precedence over other directories.
you could do brew uninstall python3 and install it from the python website here https://www.python.org/
When you go install a module you do pip3 install packageName
And when you run a program you could run it from your IDE (I recommend VSCode) or run it from the terminal with python3 drag_python_file_here
you have to use python3 instead of python on Mac so like python3 path/to/file.py and pip is now pip3 so like pip3 install pillow

google-cloud-sdk installation not finding right Python 2.7 version in CentOS /usr/local/bin

Our server OS is CentOS 6.8, I was trying to install google-cloud-sdk, even though I installed
python 2.7 in /usr/local/bin
, it is still looking at old version of
python 2.6 in /usr/bin
. I tried giving export PATH=/usr/local/bin:$PATH to first look at /usr/local/bin than /usr/bin but still the problem persists. please suggest a way to fix.
The way I have solved this (and I know it works) is to first install Python 2.7 in whatever way you'd like, then install pip using Python 2.7 which will give you pip2.7. You can then use pip2.7 to install the google_compute_engine module so that it ends up in the right modules folder.
# get pip2.7
wget https://bootstrap.pypa.io/get-pip.py
python2.7 get-pip.py
# install the gcloud module
pip2.7 install google_compute_engine
You can then add this to your $HOME/.bashrc
export CLOUDSDK_PYTHON=/usr/local/bin/python2.7
This is the best repeatable way I know of
Go to the google-cloud-sdk folder and open the install.sh file.
Change the CLOUDSDK_PYTHON="python" value to CLOUDSDK_PYTHON="python2.7"
Rerun the install with the command:
./install.sh
Or you could install it using yum:
https://cloud.google.com/sdk/downloads#yum
If you are on Windows This is a simple solution that worked for me:
open Powershell as administrator and run this to add your Python folder to your environment's PATH:
$env:Path += ";C:\python27_x64\"
Then re-run the command that gave you the original error. It should work fine.
Alternatively you could run that original (error-causing) command within the Cloud SDK Shell. That also worked for me.
I found a CLOUDSDK_PYTHON inside my ~/.bash_profile (or ~/.zshenv).
I removed it, and went back into my google-cloud-sdk directory and reinstalled it.
./install.sh
This fixed the issue for me.

Step by step: Installing Python 3.3, Lighttpd & Pymongo on Ubuntu 12.04

I'm currently migrating to new computer and I need to reinstall the software I am using which are:
Python 3.3,
Lighttpd (newest version),
Pymongo (newest version),
Ubuntu 12.04 Desktop (The System I'm using)
I started to install Python 3.3 by downloading it from the its official website (in tar.bz2 file) and by following this tutorial. Afterwards I installed Lighttpd and changed the lighttpd.conf for Python by following this tutorial, too.
I tried several paths for my cgi.assign, none of them worked. Especially /opt/python3.3/bin/python3.3 should be working, but it shows 500 - internal Server error all the time with a "hello world" test script.
Now regardless to this problem I have no clue on installing Pymongo. If I try to intall pip OR easy_install python3.3 I have to manually download it and execute the setup.py with my python3.3 executable, right? Because this always fails with an error:
`Error missing zlib on a bundle called distribute-0.7.3 (is this even the right tool I need, because it seems to be a legacy wrapper !?) or unknown url type: https for pymongo2.6.2 itself.`
I'm getting crazy with this setup. Why is this so difficult to handle? Other programs are just a few clicks to install even on a system like Ubuntu, but these particular development tools seem to be really difficult to install.If anybody has an idea on how to install all three together or has information on a better solution please help me out.
The system is used to program Python scripts in Eclipse and trying them out directly on the system (lighttpd). The database used is MongoDB. Python and MongoDB are communicating over the Pymongo driver. I am planning to use the system on a Server distribution on release and it has to be nicely scalable on a high amount of excecutions.
Thanks for your time,
It's easiest to use the Ubuntu repositories:
sudo apt-get update
sudo apt-get install python3 python3-pip lightppd python-pymongo
Or if that only installs the python2.x pymongo, use pip, which you've just installed:
sudo pip-3.3 install pymongo
Or better yet, use a virtualenv with the help of virtualenvwrapper (docs)
sudo pip install virtualenvwrapper
... # follow instructions for installing virtualenvwrapper
mkvirtualenv --python=/usr/bin/python3 -i pymongo mongoppd
workon mongoppd
... which will segregate the environment I've called 'mongoppd' from the rest of your system so you can't cause any trouble. Then you don't need sudo to pip-3.3 install things, just workon mongoppd then pip-3.3 install [...]. Or after the -i flag when you create the virtualenv to get it installed straight away.
In general, on Ubuntu, you should hardly ever have to install something manually. Your first attempt should be using sudo apt-get install (use tab-complete to see what's available or just google "ubuntu 12.04 packages [...]" and you'll find the list of packages). Then for python use pip install or pip-3.3 install as appropriate. You'll only need to run python setup.py install if you need to install a development version of a package or something obscure that's not on pip. I don't think there's a good reason to ever use easy_install these days.

Resources