Verify thread-safety MySQLdb (Python) prior to Trac installation - python

I'm trying to install Trac manually for the first time. I don't want to use a one-click-installer like Bitmani, I want to learn how to install Trac manually, so I'm following the instructions carefully. I'm installing it in a Windows localhost for now, before installing it in a Linux environment.
As I follow the instructions carefully, I needed to install Python+MySQLDb, and I read this:
thread-safety is important
(...) verify that it is thread-safe by calling MySQLdb.thread_safe() from a standalone Python script (i.e., not under Apache). If the stand-alone test reports that MySQLdb is indeed thread-safe (...)
I've just installed MySQLDb 1.2.4 and I'd like to verify this. I've Googled but I haven't found an example about this, and I have no idea about Python. How can I verify if I've got a thread-safe installation?

Run this command. If you get 1 in the output, your installation is threadsafe.
python -c "import MySQLdb ; print MySQLdb.thread_safe()"

Related

query-exporter doesn't connect to the Database - throws "module not found"

I have some set of data in the IBM DB2 database which needs to be utilized as something required for metrics. To get this accomplished I'm trying to use python's export prometheus metrics from SQL - Reference here: https://pypi.org/project/query-exporter/
Inline to this I have tried to install the ibm_db module using pip3 install ibm_db
When I list the modules I have in the cmdline, I see it available:
And Below is my config.yaml which will establish connection to poll the data from the database for the metrics to be exported to Prometheus.
In the above for the dsn, I have also tried with:
db2://user:pass#host[:port]/database , db2+ibm_db://user:pass#host[:port]/database
But ended up with the same result which is show in the below.
Now I'm trying to execute the query-exporter module using the below command:
query-exporter ~/py-query-exporter/config.yaml
But ending up with the below error:
Can someone help here why the ibm_db module is not getting identified? - I don't know if this issue is wider across different db module Also, my python version is:
vijayleom#Vijays-MacBook-Pro ~ % python -V
Python 3.8.11
Always add pertinent facts to the question, not as comments, because comments are not searchable and are easily missed.
If you cannot import ibm_db and successfully run ibm_db.connect(....) then any tools (such as SQLAlchemy or packages that use SQLAlchemy like your query-exporter) will not work - because ibm_db underpins them.
If this is a conda environment, you should use conda to install the ibm_db because conda checks dependencies more fully than does pip. Sometimes it is necessary to upgrade the pip version also (regardless of conda).
Apart from that, there are known issues with ibm_db on MacOS , but most have workarounds by now.
Two in particular may be relevant, relating to comptibility with the c libraries (which conda install ibm_db should find) and sometimes a need to export a specific value for environment variable DYLD_LIBRARY_PATH before running python.
Find the directory that contains clidriver, which by default gets installed with ibm_db module. By default it will be in the site-packages directory of your python environment (you can use pip3 show ibm_db to see the directory name ). Get the fully-qualified directory name for clidriver and append /lib to it, then use that value ( e.g. your_clidriver_path/lib , thus:
export DYLD_LIBRARY_PATH=your_clidriver_path/lib:$DYLD_LIBRARY_PATH before you run your python code.
When you cannot get a workaround, try searching for matching problems and solutions on the github-issues page for python ibm_db before opening a ticket for the developers at https://github.com/ibmdb/python-ibmdb/issues

How to install mesos.native python module in Mac OS and Ubuntu

I would like to write and run a Mesos framework with Python, so I need mesos.native module.
On Ubuntu:
I can build mesos from source code. I tried to easy_install all the generated egg files but none of them made it possible for Python to import mesos.native.
I also tried to download the egg from http://downloads.mesosphere.io/master/ubuntu/14.04/mesos-0.20.1-py2.7-linux-x86_64.egg and easy_install it, which didn't work as well.
On Max OS:
Got some problem building the mesos source code because of the issue. So I am wondering whether there is an easy way to install the Python module without building the source code.
BTW, why don't they make the mesos.native pip-installable like mesos.interface?
Problem solved: https://github.com/RobinDong/mesos-python-examples/blob/master/calculate_pi/pi_run
I just need to set PYTHONPATH as that in the file and run python. Mesos.native can be successfully loaded.

Getting the correct version of Pmw to install

Problem:
I'd like to install Pmw 2.0.0 (project page here) so that I can use it with tkinter in python3. The setup script from the package detects which version of python you're using and installs the version that is appropriate for your system (Ubuntu 15 in my case). I can't find any references to switches to make it install the 2.0.0 instead of 1.3.3(the Python 2.7 version), nor have I been able to get the script to install to the python3 libraries.
What I've done so far:
I've changed the python version detector in the setup script from
if sys.version_info[0]<3:
version='2.0.0' # really '1.3.3'
packages=['Pmw', 'Pmw.Pmw_1_3_3', 'Pmw.Pmw_1_3_3.lib',]
to
if sys.version_info[0]<2:
version='2.0.0' # really '1.3.3'
packages=['Pmw', 'Pmw.Pmw_1_3_3', 'Pmw.Pmw_1_3_3.lib',]
to attempt to force the installer to default to the python3 version, which it does, but it installs them in the python2.7 libraries (/usr/local/lib/python2.7/distpackages).
What I want to do:
I'm looking for a way to force the installer to put the 3.4-compatible package into the python3 libraries. If that means getting it to install both packages in their respective correct directories, that's fine, too. I'm stumped about what to try next.
Answered by RazZiel on AskUbuntu:
Link here.
Instead of using the command sudo python setup.py build and then sudo python setup.py install, I should have been using python3 to execute the setup script. I've managed to outthink myself pretty badly on this one.

biopython test_Tutorial ... FAIL

I'm fairly new to programming. I'm trying to install biopython on mac os x 10.5.
This is what I did so far. 1. installed xcode 2. installed numpy 3. ran these commands in terminal python setup.py build python setup.py test
test reported back one fail.
test_Tutorial ... FAIL
ERROR: Run tutorial doctests.
Traceback (most recent call last): File "test_Tutorial.py", line 152, in test_doctests ValueError: 4 Tutorial doctests failed: test_from_line_05671, test_from_line_06030, test_from_line_06190, test_from_line_06479
Thanks for any help or advice.
That file test_Tutorial.py runs marked examples in the source for the main Biopython Tutorial and Cookbook ( http://biopython.org/DIST/docs/tutorial/Tutorial.html / http://biopython.org/DIST/docs/tutorial/Tutorial.pdf ) to check the examples work as expected. Internally this uses the same library as Python's doctest examples.
The fact that test_Tutorial.py failed is probably a harmless issue with a couple of examples.
Which version of Biopython are you using? If this was an official release that failure is unexpected. If it was a snapshot from the git repository then that is unfortunate. If you are curious, you could try this to see more information:
$ cd Tests
$ python test_Tutorial.py
This kind of issue might be more easily discussed on the Biopython mailing list http://biopython.org/wiki/Mailing_lists
I've found that the easiest way to set up a good programming environment is to use MacPorts, as it has a great way of ensuring that all dependencies are satisfied when installing things. You'll need to be familiar with Terminal and the command line, though.
Install MacPorts for OSX 10.5. Read the documentation too.
Restart.
Open Terminal.app and enter sudo port selfupdate to make sure the portfile definitions are up to date.
Run sudo port install py27-biopython to install the latest version of Python 2 (2.7.3), numpy, and biopython. This will take a while.
Run echo $PATH and make sure that /opt/local/bin and /opt/local/sbin` are at the beginning. They should be.
Run which python and ensure it returns /opt/local/bin/python. If it doesn't, run sudo port install python_select and follow its instructions to select your default python version.
Hopefully, at this point you can run python to enter the interactive interpreter, and import Bio won't give any errors.
Good luck!

Cannot load Python bindings for MySQL - Trac

I recently started getting the following error in my trac install:
Cannot load Python bindings for MySQL
I, unfortunately, had to reinstall MySQL, and, afterwards, I started getting those issues. I have spent the last hour trying to track something down on Google, but I couldn't get anything to work. I made sure MySQL is up and running correctly. I created a new MySQL user specific to trac. I made sure all of the packages are there there. Nothing.
Here's my dkpg (I run Ubuntu Maverick):
dpkg -l | grep python
libapache2-mod-python
libapache2-mod-python-doc
libpython2.6
libpython3.1
python
python-central
python-docutils
python-genshi
python-imaging
python-lxml
python-minimal
python-mysqldb
python-pkg-resources
python-pybabel
python-pygments
python-roman
python-setuptools
python-subversion
python-support
python-tz
python2.6
python2.6-minimal
python3.1
python3.1-minimal
If anyone has any ideas as to what it could be, I'd be forever grateful.
That error should result when Trac tries to do "import MySQLdb" but it fails. You do have the right package in place which should provide that module, but for some reason it's failing. To find out why, you should look at the environment in which Trac is running. Is it using a Python other than /usr/bin/python2.6? Does it have a $PYTHONPATH set?
You may also want to try importing MySQLdb directly:
/usr/bin/python2.6 -c 'import MySQLdb'
That should have no output if the package can be loaded as expected.
Lastly, this may not be related, but you know that Maverick is no longer supported, right? It won't get any security updates or other support from Ubuntu.
Edit:
The python2.6 import worked fine, so we need to look closer at the trac environment. One way to do this will be to edit the db/mysql_backend.py file and insert some debugging information. (If this is an OS-packaged install, you should find that file under /usr/lib/python2.6/dist-packages/trac/; otherwise, you probably know where you put it). Let's try changing the MySQLConnector.get_supported_schemes() method, since I'm not sure where plain prints will show up for you.
def get_supported_schemes(self):
if not has_mysqldb:
import sys
self.error = "Cannot load Python bindings for MySQL. sys.path = %r, sys.executable = %r" \
% (sys.path, sys.executable)
yield ('mysql', -1 if self.error else 1)
instead of calling a specific python install like the paul is suggesting, try this at your terminal:
launch the path's python instance
python
see if you can import mysqldb
import MySQLdb
also run for us a:
pip freeze
we should see a mysql-python in the output

Categories