Read other questions; unfortunately they were not relevant.
Using this tutorial:
http://lpsolve.sourceforge.net/5.5/Python.htm
Found this file:
lp_solve_5.5.2.0_exe_ux32
That contains these files:
libbfp_etaPFI.so
libbfp_GLPK.so
libbfp_LUSOL.so
libxli_CPLEX.so
libxli_DIMACS.so
libxli_LINDO.so
libxli_MathProg.so
libxli_XPRESS.so
libxli_ZIMPL.so
lp_solve
The tutorial says the need file is:
lpsolve55.so
How do you get lpsolve working with Python in Ubuntu?
This is for installing lpsolve55 in Python, anaconda in ubuntu distribution, translated from the blogpost (which is in Chinese)
go download at sourceforge
lp_solve_5.5.0.20_dev.tar.gz - where you would find liblpsolve55.so and some other files
lp_solve_5.5.0.20_Python_source.tar.gz - where you would find lpsolve55.so and setup.py
make sure you have install python-dev (if not, type sudo apt-get install python-dev at the command line)
unzip lp_solve_5.5.0.20_Python_source.tar.gz and put the file at anaconda2/lib/python2.7/site-packages/
unzip lp_solve_5.5.0.20_dev.tar.gz and put "only" the liblpsolve55.so at anaconda2/lib, and the rest at anaconda2/lib/python2.7/site-packages/lp_solve_5.5, the directory you get at step 3, in the same layer as extra. The result would look like this
Now
$ cd anaconda2/lib/python2.7/site-packages/lp_solve_5.5/extra/Python/
$ python setup.py install
Test by import lpsolve55
You will need this file:
lp_solve_5.5.2.0_Python2.5_exe_ux64.tar.gz
Inside it you will find: liblpsolve55.so
You need to put that file in a place accessible to the python path. Had problems doing that so it's in the project's folder.
You also need this file:
lp_solve_5.5.2.0_dev_ux64.tar.gz
Inside it you will find:
liblpsolve55.so
This file needs to go to /lib/usr
Related
I found this great module on within and downloaded it as a zip file. Once I extracted the zip file, i put the two modules inside the file(setup and the main one) on the module folder including an extra read me file I needed to run. I tried installing the setup file but I couldn't install it because the console couldn't find it. So I did some research and I tried using pip to install it as well, but that didn't work. So I was wondering if any of you could give me the steps to install it manually and with pip (keep in mind that the setup.py file needs to be installed in order for the main module to work).
Thanks!
The cleanest and simplest way I have found is to use pip from within QPython console as in This Answer
import pip
pip.main(['install', 'networkx'])
Step1: Install QPython.
Step2: Install AIPY for QPython.
Step3: Then go to QPython-->QPYPI-->AIPY and install from there Numpy, SciPy, Matplotlib, openCV etc.
Extract the zip file to the site-packages folder.
Find the qpyplus folder in that Lib/python3.2/site-packages extract here that's it.Now you can directly use your module from REPL terminal by importing it.
I have a package I am installing in Python that requires dependancies or it fails to install:
> pip install http://etc
pak/test.cpp:3:10: fatal error:
'tools/test.cv' file not found
#include "tools/test.cv"
I have been infomred that I need to download the files (which I have done) then...
create a file ~/.tools.cfg containing:
[build_ext]
include_dirs=/path/to/home/tools
However, I don't understand this last part!
How does the pip installer pick up the .tools.cfg file, where do I even create the file .tools.cfg?
I'm running this on a mac if thats makes a difference.
According to the path you gave, you make the file in your home directory. On a Mac (OS X, I assume), that is a sub-directory of /Users named for your user name (i.e. /Users/Sputnik). You can create it with any text editor, i.e. emacs, vim, nano, TextEdit.app, etc.
I don't know exactly how the pip installer is looking up that file, but presumably it's looking for a file with the name of the package (in this case, tools).
Please comment if this doesn't answer your question, and accept (i.e. click on the Checkmark) if it does!
I built libsvm on Mac OS X with Make.
$ tar xzfv libsvm-3.17.tar.gz
$ cd libsvm-3.17
$ make
This built the various libsvm binaries:
$ ls
COPYRIGHT heart_scale svm-predict.c svm-train.c tools
FAQ.html java svm-scale svm.cpp windows
Makefile matlab svm-scale.c svm.def
Makefile.win python svm-toy svm.h
README svm-predict svm-train svm.o
I also linked to this in /usr/local:
$ ls -la /usr/local/
...
svm -> /usr/local/libsvm-3.17/
And appended the Python bindings to my path:
import sys
sys.path.append('/usr/local/svm/python')
But the Python bindings cannot find the "LIBSVM" library:
$ python test.py
Traceback (most recent call last):
File "test.py", line 8, in <module>
import svmutil
File "/usr/local/svm/python/svmutil.py", line 5, in <module>
from svm import *
File "/usr/local/svm/python/svm.py", line 22, in <module>
raise Exception('LIBSVM library not found.')
Exception: LIBSVM library not found.
Can anyone tell me how to set this up? In the python readme for libsvm the only description is
Installation
============
On Unix systems, type
> make
The interface needs only LIBSVM shared library, which is generated by
the above command. We assume that the shared library is on the LIBSVM
main directory or in the system path.
What am I missing?
Instead of going through libsvm in order to access it with Python (I installed libsvm through MacPorts, and import svmutil fails), you might want to install the popular scikit-learn package, which contains an optimized version of libsvm with Python bindings.
The install is very simple with MacPorts: sudo port install py27-scikit-learn (adapt py27 to whatever version of Python you use).
Seems like a old thread. Hope it helps someone else in the future.
I had the same problem. The solution is
Run make in libsvm-3.0 directory
Run make in libsvm-3.0/python directory
If you did only at libsvm-3.0 folder you will face this issue. Do it at both the folders. Then it will work fine.
In case you need a non-MacPorts solution, see this page (especially the comment from Thanassis):
Installing libsvm-3.0 for Python on OSX 10.6
Despite the title of the post, the solution worked for me on a CentOS machine with python 2.7.
find_library in python is only looking at files with an extension of .so. In order for this to work correctly you need to create a libsvm.so:
% ln -s libsvm.so.2 libsvm.so
Then try this again, it will work correctly.
You do not need to use scikit learn in order to use libSVM. I had the same issue when loading the libsvm modules through python. I cloned the project from github and run build it from the command-line with make, and after setting the enviroment, I got the same error.
I fixed the issue by installing libSVM through homebrew:
brew install libsvm
This do not include the python specific binaries, so you would still have to clone and make from github and set up the environment.
You should go into /python and make to generate .so.1 file
you can also try to use homebrew to install the libsvm like 'brew install libsvm',then you can open your project file and copy the 'svmutil.py' and 'svm.py' files to the project floder,then you can use the command 'from svmutil import *',and maybe it will be ok.
Until now, my project had only .cpp files that were compiled into different binaries and I managed to configure CPack to build a proper debian package without any problems.
Recently I wrote a couple of python applications and added them to the project, as well as some custom modules that I would also like to incorporate to the package.
After writing a setup.py script, I'm wondering how to add these files to the CPack configuration in a way that setup.py get's executed automatically when the user installs the package on the system with dpkg -i package.deb.
I'm struggling to find relevant information on how to configure CPack to install custom python applications/modules. Has anyone tried this?
I figured out a way to do it but it's not very simple. I'll do my best to explain the procedure so please be patient.
The idea of this approach is to use postinst and prerm to install and remove the python application from the system.
In the CMakeLists.txt that defines the project, you need to state that CPACK is going to be used to generate a .deb package. There's some variables that need to be filled with info related to the package itself, but one named CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA is very important because it's used to specify the location of postinst and prerm, which are standard scripts of the debian packaging system that are automatically executed by dpkg when the package is installed/removed.
At some point of your main CMakeLists.txt you should have something like this:
add_subdirectory(name_of_python_app)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "fake-package")
set(CPACK_PACKAGE_VENDOR "ACME")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake-package - brought to you by ACME")
set(CPACK_PACKAGE_VERSION "1.0.2")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "2")
SET(CPACK_SYSTEM_NAME "i386")
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ACME Technology")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6), libgcc1 (>= 1:3.4.2-12), python2.6, libboost-program-options1.40.0 (>= 1.40.0)")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/name_of_python_app/postinst;${CMAKE_SOURCE_DIR}/name_of_python_app/prerm;")
set(CPACK_SET_DESTDIR "ON")
include(CPack)
Some of these variables are optional, but I'm filling them with info for educational purposes.
Now, let's take a look at the scripts:
postinst:
#!/bin/sh
# postinst script for fake_python_app
set -e
cd /usr/share/pyshared/fake_package
sudo python setup.py install
prerm:
#!/bin/sh
# prerm script
#
# Removes all files installed by: ./setup.py install
sudo rm -rf /usr/share/pyshared/fake_package
sudo rm /usr/local/bin/fake_python_app
If you noticed, script postinst enters at /usr/share/pyshared/fake_package and executes the setup.py that is laying there to install the app on the system. Where does this file come from and how it ends up there? This file is created by you and will be copied to that location when your package is installed on the system. This action is configured in name_of_python_app/CMakeLists.txt:
install(FILES setup.py
DESTINATION "/usr/share/pyshared/fake_package"
)
install(FILES __init__.py
DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)
install(FILES fake_python_app
DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)
install(FILES fake_module_1.py
DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)
install(FILES fake_module_2.py
DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)
As you can probably tell, besides the python application I want to install there's also 2 custom python modules that I wrote that also need to be installed. Below I describe the contents of the most important files:
setup.py:
#!/usr/bin/env python
from distutils.core import setup
setup(name='fake_package',
version='1.0.5',
description='Python modules used by fake-package',
py_modules=['fake_package.fake_module_1', 'fake_package.fake_module_2'],
scripts=['fake_package/fake_python_app']
)
_init_.py: is an empty file.
fake_python_app : your python application that will be installed in /usr/local/bin
And that's pretty much it!
A setup.py file is the equivalent of the configure && make && make install dance for a standard unix source distribution and as such is inappropriate to run as a part of a distributions package install process. See this discussion of the different ways to include Python modules in a .deb package.
I'm currently trying to learn Python and am going through How to Think Like a Computer Scientist: Learning With Python. I have installed Python 2.6.2 on Mac OSX 10.4.11 and am using the IDLE.
At the end of chapter 4 Elkner et al. refer to GASP. However their instructions don't work as when I enter:
>>> from gasp import*
I get:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
from gasp import*
ImportError: No module named gasp
I've had a look around on google and can only find outdated methods of installation or pages of gobbledegook. I believe I have to install PyObjC first and haven't been able to accomplish this either.
Can anyone please help me out with some plain English instructions?
Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, as I am (very first day messing with this stuff, e.g., terminal). This is the result of hours of Googling that was all done in one day. Perhaps someone who is familiar with the commands below (in bold) wouldn’t mind explaining what exactly is taking place. Additionally, this was all done in terminal on a MacBook Pro running Mac OS Lion.
Install macport binary (comes with installer; easy)
sudo port install py-game
not sure if this is necessary, as it doesn’t appear to cause pygame to be functional for python version 2.7.1 (stock python on lion)
sudo port select --set python python 2.7
I believe this set the default python version to 2.7.2 which I also believe was
downloaded during step 2 (therefore why I think this ends up being a necessary step)
Download setuptools-0.6c11-py2.7.tar
In folder gasp-0.3.4, which appears after clicking on the .tar, place setup.py in the
gasp folder
sudo python gasp/setup.py install
make sure your directory is the folder gasp-0.3.4
sudo port –v install py27-pygtk
takes about an hour for this step to complete
sudo port uninstall py-game
this step is not necessary for gasp to work; I simply didn’t want any unnecessary
stuff on my computer that was downloaded during the second step; however, this step
put python 2.7.2 on my computer; could install 2.7.2 separately I guess but this way
worked for me; a lot of other unnecessary stuff is installed during this step too but
I think it’ll remain even after this command, oh well
This is actually somewhat of a coincidence; I'm one of the packagers of GASP. On our download page, which is linked by our main project page, there are instructions on how to install it on most major platforms. Hadn't considered OSX, however. Will write something up shortly.
Essentially, install the Official Python from the PSF. Then add MacPorts and run
sudo ports install py-game
Extract the source tarball from the download page linked above to your site-packages directory.
There are also some alternative instructions I found that might work better, as I have not tested the above.
This is an interesting problem faced by most of the readers using "How to Think Like a Computer Scientist : Learning with Python", when they reach 4th chapter.
Now to install GASP, you need to check whether you have python installed on your machine.
Assumption: I am going to assume that you are using Mac.
Type the following command on your terminal,
`$ python -V`
{If your system has python installed on it, you will get an answer like Python 2.7.1 ( if the version is 2.7.1).}
Once you have python available on your system, you should install PyObjC.
An easy way out is to type on to your terminal prompt,
`$ easy_install pyobjc==2.2`
{this will install the version 2.2}
Next step is to install pygame package , you can do this in two ways either by downloading the .dmg file or using "homebrew". I prefer the second method.
to install pygame package using "brew" you have to install mercurial first. It's a simple procedure, just type in
$ brew install mercurial
Then type in the following commands,
$ brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi
$ sudo pip install hg+http://bitbucket.org/pygame/pygame
Next step is to install GASP. Download gasp from https://launchpad.net/gasp-core/+download
Extract the .tar file, you will get a folder structure. Our aim is to copy the folder named "gasp" to the Systems Library folder. To check which folder or version of python is used and to know their correct path type in the following command on terminal.
$ python -c 'import sys, pprint; pprint.pprint(sys.path)'
generally it will print a path similar to '/Library/Python/2.7/site-packages' , you can notice this either as the last line or the second last line of the output that above commands generate.
Copy the gasp folder to the site-packages folder,
$ sudo cp -R ~/Desktop/python-gasp-0.1.1/gasp/ /Library/Python/2.7/site-packages/gasp
This should copy all the required files to the location specified as the second argument.
Now go to terminal and type
$ python
>>> import gasp
If everything goes fine, you will not get any error or any messages.
PS: Ensure that in your site-packages directory there are no duplicate copies of pygame/gasp. In case of duplicates, it may throw lots of tantrums. Also, if any of the steps go wrong you may get error "import cairo" some 25th or 26th line on base.py in gasp package.In that event, please clean up your site packages directory by removing pygame and gasp and re-install them, that should solve it.
Also while installing mercurial you may get some warning related to Certificates. You can solve them by typing in following commands,
$ openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650
$ sudo cp dummycert.pem /etc/hg-dummy-cert.pem
$ cd ~
$ nano .hgrc
{ This will open up an empty .hgrc file }
Type in the following
[web]
cacerts = /etc/hg-dummy-cert.pem
save the above 2 lines by pressing ctrl+ o
exit nano by pressing ctrl + x
Thats it. This should solve your problems with GASP installation and enjoy the book " How to Think Like a Computer Scientist" it's a wonderful introduction to the world of computing.