How should I handle software packages? - python

I am trying to install pysqlite and have troubles with that. I found out that the most probable reason of that is missing sqlite headers and I have to install them. My platform: CentOS release 5.3 (Final). I have Python-2.6.2.
I also found out that I need .rpm files. As far as I have them I execute:
rpm -i sqlite3-devel-3.n.n.n.rpm
and everything should be fine.
However, I do not know where to find sqlite3-devel-3.n.n.n.rpm file. Should it already be on my system? I could not locate it with "locate sqlite3-devel-3". Should I download this file? If yes where I can find it and which version should I use? I mean, the .rpm file should be, probably, consistent with the version of sqlite that I have on my computer? If it is the case, how can I find out the version of my sqlite?
If I type "from pysqlite2 import dbapi2 as sqlite" I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pysqlite2
"yum search pysqlite" gives me the following:
Loaded plugins: fastestmirror
Excluding Packages in global exclude
list Finished
==== Matched: pysqlite ==== python-sqlite.x86_64 : Python bindings
for sqlite.
By the way, I have the following directory:
/home/myname/opt/lib/python2.6/sqlite3
and there I have the following files:
dbapi2.py dbapi2.pyc dbapi2.pyo
dump.py dump.pyc dump.pyo
__init__.py __init__.pyc __init__.pyo test
If I type "import unittest" and then "import sqlite3 as sqlite" I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/myname/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import * File "/home/myname/opt/lib/python2.6/sqlite3/dbapi2.py",
line 27, in <module>
from _sqlite3 import * ImportError: No module named _sqlite3
Thank you in advance.

Python 2.6 (and some earlier) include sqlite Python org library ref so you should not need to do this. Just import it and run

You can use buildout to create localized version of your project. This will install all necessary packages without having sudo access to the server.
To give it try, do the following:
mkdir tmp
cd tmp
wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
python bootstrap.py init
vim buildout.cfg
edit buildout.cfg and replace it with following:
[buildout]
parts = sqlite
[sqlite]
recipe = zc.recipe.egg
eggs = pysqlite
interpreter = mypython
Now, run ./bin/buildout to rebuild the project. This will download all of the necessary packages and create a new interpreter for you that you can use test that you can access sqlite.
./bin/buildout
./bin/mypython
>>> import sqlite3
This gives you a controlled environment that you can use to develop inside of.
To learn more about buildout, you can watch videos from pycon 2009 on Setuptools, Distutils and Buildout.
Eggs and Buildout Deployment in Python - Part 1
Eggs and Buildout Deployment in Python - Part 2
Eggs and Buildout Deployment in Python - Part 3
Good luck

Typically, you should install the python sqlite module through yum, something like:
yum install python-sqlite
and then edit your code changing sqlite2 references to sqlite3.
By the way, whenever you read directions to install sqlite3-devel-3.n.n.n.rpm, the n parts are not literal; they're supposed to be replaced with numbers specifying a version of the rpm package.

Related

Cannot install custom python module

I am having trouble installing a custom python module I have written.
Here are my steps so far:
Navigate to the module directory C:\Users\myname\repos\mymodulename where the setup.py file is in the anaconda prompt. Type: python setup.py install
The command prompt returns (plus some other things)
Extracting mymodulename-0.1-py3.7.egg to c:\users\myname\appdata\local\continuum\anaconda3\lib\site-packages
mymodulename 0.1 is already the active version in easy-install.pth
Installing myclass-script.py script to C:\Users\myname\AppData\Local\Continuum\anaconda3\Scripts
Installing myclass.exe script to C:\Users\myname\AppData\Local\Continuum\anaconda3\Scripts
Installed c:\users\myname\appdata\local\continuum\anaconda3\lib\site-packages\mymodulename-0.1-py3.7.egg
Processing dependencies for mymodulename==0.1
...
Using c:\users\myname\appdata\local\continuum\anaconda3\lib\site-packages
Finished processing dependencies for mymodulename==0.1
To me that looks like it has installed. Opening up the console and trying to import:
>>> import mymodulename.myclassas ce
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mymodulename'
>>>
It appears in hasn't. Checking the list of modules in anaconda with help('modules') confirms that it has not been imported.
I thought that perhaps i had installed it to the wrong environment:
(base) C:\Users\myname>conda env list
# conda environments:
#
base * C:\Users\myname\AppData\Local\Continuum\anaconda3
py2 C:\Users\myname\AppData\Local\Continuum\anaconda3\envs\py2
Only a python 2 environment which mymodule wouldn't be compatible with.
Does anyone have any suggestions about what I can try to resolve this? Happy to elaborate on any of the points
Thanks in advance.
EDIT: Some more information that may be relevant.
This package was initially installed in site-packages. I have reinstalled there and the package works. The reason I moved the package is because I am aware it is bad practice to store custom packages there.

Python GUI2Exe Application Standalone Build (Using Py2Exe)

I am trying to build a Python Script into a stand alone application. I am using GUI2Exe. My script uses selenium package. I have it installed.
Project compiles fine and runs on python command line directly but fails to build a stand alone because it is referring to folder:
ERROR: test_file_data_extract (__main__.FileDataExtract)
----------------------------------------------------------------------
Traceback (most recent call last):
File "File_data_extract.py", line 18, in setUp
File "selenium\webdriver\firefox\firefox_profile.pyc", line 63, in __init__
IOError: [Errno 2] No such file or directory: 'C:\\users\\username\\PycharmProjects\\Python_27_32bit\\file_data_extract\\dist\\File_data_extract.exe\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
It is looking for selenium package is located at :
C:\Users\username\Anaconda2_Py27_32bit\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\firefox
where C:\Users\username\Anaconda2_Py27_32bit is where I installed Anaconda Python 2.7, 32 bit version. By default it is looking for in \dist\filename.exe folder.
I was able to build it using bbfreeze. It works great.
First I had to install bbfreezee via pip (one time only):
pip install bbfreeze
Create a build_package.py file as:
from bbfreeze import Freezer
f = Freezer("project_name", includes=("selenium","SendKeys",)) #list problem packages here to manually include
f.addScript("project_name_script.py")
f() # starts the freezing process
Build project:
python build_package.py bdist_bbfreezee
in folder project_name where project_name_script.py sits you find project_name_script.exe with all the include packages including selenium and sendkeys. When you distribute the package you need to distribute entire project_name because it contains all dependent library dlls (python .pyd).
More details refer official bbfreezee here:
https://pypi.python.org/pypi/bbfreeze/#downloads

Cannot import distutils from within a py2exe-compiled script

I am on Windows Server 2012R2, trying to compile a script with py2exe, within a virtualenv, and I'm getting issues whenever one of the application scripts tries to "import distutils" (in my case, it's somewhere inside a 3rd-party library, but I reduced the problem here).
Steps to reproduce:
Create a virtualenv
virtualenv venv
call venv\Scripts\activate
Install py2exe inside the virtualenv
easy_install --always-unzip py2exe-0.6.9.win64-py2.7.amd64.exe
Create setup.py
from distutils.core import setup
try:
import py2exe
except:
pass
setup(
console=[
'py2exe_distutils.py'
]
)
Create py2exe_distutils.py
import distutils
Run py2exe
python setup.py py2exe
Try to run the generated executable
dist\py2exe_distutils.exe
It returns:
C:\Users\root\p\dist\library.zip\distutils\__init__.py:14: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
File "py2exe_distutils.py", line 6, in <module>
import distutils
File "distutils\__init__.pyc", line 25, in <module>
ImportError: cannot import name dist
The script runs fine when I run it directly (python py2exe_distutils.py), even from within the virtualenv.
Am I trying to do something unsupported by py2exe, or is something wrong with my setup?
I had the same problem while creating an executable that used pandas 0.12.0. This worked for me: before you create the executable, copy the distutils folder from the base python installation
robocopy C:\Python27\Lib\distutils venv\Lib\distutils /E /COPY:DAT
I am using virtualenv 12.0.4 and py2exe 0.6.6 on Windows 7 Professional. Some extra insight can be found here. This answer pointed me in the direction of just copying the files.

Python bindings for libtorrent-rasterbar are not working

I'm running Debian 6.0.6
I've downloaded latest version of libtorrent-rasterbar from here: http://code.google.com/p/libtorrent/downloads/detail?name=libtorrent-rasterbar-0.16.6.tar.gz&can=2 and installed it:
./configure --enable-python-binding
make
make install
cd bindings/python
python setup.py build
python setup.py install
now I want to test whether the library works:
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libtorrent-rasterbar.so.7: cannot open shared object file: No such file or directory
The packaged version of libtorrent from the distributive's repository had some funny behaviour (complaining on boost dependences), so I've decided to upgrade. The same situation is on both of my debian boxes, yet ubuntu box is fine.
old error message from my debian box:
File "ar.py", line 15, in create
s.start_dht()
Boost.Python.ArgumentError: Python argument types in
session.start_dht(session)
did not match C++ signature:
start_dht(libtorrent::session {lvalue}, libtorrent::entry)
Search for the shared object file and add it to your path.
sudo updatedb
locate libtorrent-rasterbar.so.7
This should output /<path_to_directory>/libtorrent-rasterbar.so.7
Add this to your ~/.profile or temporarily tell Python where to look:
export LD_LIBRARY_PATH=/<path_to_directory>/
See more detailed installation instructions here.

How can I make Python see sqlite?

I cannot use sqlite3 (build python package), for the reason that _sqlite3.so file is missing. I found that people had the same problem and they resolved it here. To solve my problem I have to "install sqlite3 and recompile Python". I also found out that the problem can be solved by "building from source and moving the library to /usr/lib/python2.5/lib-dynload/".
As I have been told to here, I have to install sqlite from the source and copy newly compiled files to my Python directory (nothing was said about "recompile Python"). Well, I have installed sqlite and now I have to copy something to my /lib-dynload/ directory.
I am not sure what exactly I should copy. In my /lib-dynload/ directory I have only .so files. And in my sqlite-3.6.18 I do not have any *.so files (it makes me suspicious). I had this problem since I did not have _sqlite3.so file in /lib-dynload/. By compilation of sqlite I got some new files (for example sqlite3.o and sqlite3.lo) but not _sqlite3.so.
P.S. Some details:
1. I use Python 2.6.2 (which I installed locally).
2. I do not have root permissions.
3. I had already sqlite installed globally on the machine by root.
4. I just installed sqlite locally.
5. My OS is CentOS release 5.3 (Final).
6. When I type in Python command line import sqlite3 I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/loctopu/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/loctopu/opt/lib/python2.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
I don't have exact answer, but few hints here
To install python from source, you don't need to be root, you can always install at /home/USERNAME/usr, for example when you do configure, do like ./configure --prefix=/home/USERNAME/usr
Installing sqlite binaries does not mean its included python extension (instead, sqlite dev files are needed when you compile python)
proper import usage of sqlite3 is import sqlite3

Categories

Resources