No module named 'mysql' - python

I've created a Python script to store data in MySQL. It works properly in PyCharm. When converted to an exe file it does not work.
This is traceback from the command line:
Traceback (most recent call last):
File "myscript.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
[8428] Failed to execute script 'myscript' due to unhandled exception!
The command to create the exe:
pyinstaller --onefile --console CoinVolumes.py
I also tried auto-py-to-exe but got the same error. Mysql is installed.

use this command:
pip install mysql-connector-python
after that verify:
$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>

In Python 3.6.9 I can use Pip 3 and do following:
pip3 install mysql
pip3 install mysql-connector-python

You would need to run the mysql server yourself. Pyinstaller is working properly, the problem here is that mysql server is not part of python, therefore you need to start the server mannualy. An alternative is to use sqlite, which does not require a server. It is built into standard python, no need for installing anything.

Related

Unable to import package after installing with Anaconda

I have installed Redis using Anaconda on MaxOSX Catalina
(base) ➜ ~ conda list | grep redis
redis 5.0.3 h1de35cc_0
(base) ➜ ~ which python
/Users/me/anaconda3/bin/python
(base) ➜ ~ python
Python 3.7.3 (default, Mar 27 2019, 16:54:48)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'redis'
>>>
After searching across the web, and trying a couple of things, among them changing the sequence in my $PATH variable, I am still unable to get python to recognize the package.
Just for completeness, my PATH variable looks like this:
PATH=/Users/me/Library/Python/3.7/bin:/usr/local/smlnj/bin:/Users/me/anaconda3/bin:/Users/me/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Apple/bin:/usr/local/go/bin:/usr/local/go/bin:/Users/me/Development/gocode/bin
The Python package that provides interface for Redis is distinct from the redis package. Instead you need
conda install redis-py
I tried installing redis using
conda install redis
Then I tried to use the redis package using import redis and I could replicate the same error you got.
FIX :
Try installing redis in the anaconda terminal using
pip install redis
and then tried
import redis
This works fine

Error while installing package developed with cliff

I wrote a command line tool with cliff 2.3.0, tested on my laptop (Mac, Python 2.7.12). When I was tried to install it (python setup.py install) on a server (Linux, Python 2.7.2), I encountered this error:
Installed /private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg
ERROR:root:Error parsing
Traceback (most recent call last): File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-> py2.7.egg/pbr/core.py", line 111, in pbr
attrs = util.cfg_to_args(path, dist.script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 248, in cfg_to_args
kwargs = setup_cfg_to_setup_kwargs(config, script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 431, in setup_cfg_to_setup_kwargs
if pkg_resources.evaluate_marker('(%s)' % env_marker):
AttributeError: 'module' object has no attribute 'evaluate_marker' error: Setup script exited with error in setup command: Error parsing /private/tmp/easy_install-EGMO15/cliff-2.3.0/setup.cfg: AttributeError: 'module' object has no attribute 'evaluate_marker'
Any suggestions?
It looks like your server may have a (much) older version of the setuptools package installed (which provides the pkg_resources module). The evaluate_marker method looks as if it first showed up at the end of 2014, so if you're using an older system it is possible that method is not available.
Depending on your environment, you may be able to simply pip install -U setuptools, or you may need to see if your distribution has a newer isntallable package available.
If you can update your question to include details about your server's operating environment (what distribution and version are you running? What version of Python? What version of setuptools?), we can probably provide a more complete answer.
Update
For example, Ubuntu 12.04 only has setuptools 0.6, and the pkg_resources module (which is packaged in the python-pkg-resources package) does not have the evaluate_marker method:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'evaluate_marker'
In this environment, I can install pip:
# apt-get install python-pip
And then upgrade the installed version of setuptools:
# pip install -U setuptools
And now:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
<function evaluate_marker at 0x1535050>
>>>
NB Upgrading distribution packages (e.g., things installed by apt-get in this example) using pip can often lead to sadness and heartache, and you are much better off if you are able to upgrade the underlying environment to one where such workarounds are not necessary. Alternatively, running your code from a Python virtual environment (so that your upgraded packages do not override system packages) is also a technically better solution.

ImportError: No module named 'paramiko'

I have done through the other questions online here, and I feel that mine is different enough to warrant a new question.
So I have a Centos 6 box, which is running a small website for me, acts as an office git server and I am trying to configure Python3 on it.
So I followed the following these steps to set up python3 on the server. However it seems that I cannot import paramiko into my script.
I downloaded the paramiko rpm however I get this message:
When I try to import paramiko I get:
[root#GIT Python-3.4.2]# rpm -ivh /usr/lib/Python-3.4.2/Modules/python-paramiko-1.7.5-2.1.el6.noarch.rpm
Preparing... ########################################### [100%]
package python-paramiko-1.7.5-2.1.el6.noarch is already installed
When I run python3 directly:
[root#GIT inserv_health_check]# python3
Python 3.4.2 (default, Jan 21 2015, 06:28:04)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paramiko
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'paramiko'
>>>
I am sure there is a simple solution to this problem perhaps the path is wrong, or I should have put a symbolic link in somewhere. Any help would be appreciated :)
Before anyone asks, which python output:
[root#GIT Python-3.4.2]# which python
/usr/bin/python
[root#GIT Python-3.4.2]# which pytho~n3
/usr/bin/which: no pytho~n3 in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root#GIT Python-3.4.2]# which python3
/usr/local/bin/python3
Thanks
You need to do pip install paramiko so that python sees that module. If you work on a virtual environment, you need to workon <env_name> first and then pip install the desired module.
type pip3 install paramiko
if you want to install it for python3

cx_Oracle problem trying to import python

I am trying to run python in an Apache WS in a linux RHEL x86_64.
After Install and configure Python2.5 and Apache, I install Oracle Instant Client (basic and sdk) in a by an .rpm file withou any problem.
oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm
I set the envoirment variables
export ORACLE_HOME=/appl/paths/instantclient_10_2
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
Then install cx_Oracle by an .rpm file too and again withou any problem.
cx_Oracle-5.0.3-10g-unicode-py25-1.x86_64.rpm
When I try to import cx_Oracle in python I got the message
Python 2.5.2 (r252:60911, Jul 1 2010, 17:47:36)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /appl/paths/python2.5/site-packages/cx_Oracle.so: undefined symbol: OCIDBShutdown
I google for answers without success. Any tip?
The problem was in the ORACLE_HOME, there was a misspelling on it
I solved the same problem by installing an older version of cx_Oracle (4.3.1 instead of 5.1.2). Just for future reference.

Cannot import SQLite with Python 2.6

I'm running Python 2.6 on Unix and when I run the interactive prompt (SQLite is supposed to be preinstalled) I get:
[root#idev htdocs]# python
Python 2.6 (r26:66714, Oct 23 2008, 16:25:34)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sqlite
>>>
How do I resolve this?
The error:
ImportError: No module named _sqlite3
means that SQLite 3 does not find the associated shared library. On Mac OS X it's _sqlite3.so and it should be the same on other Unix systems.
To resolve the error you have to locate the _sqlite3.so library on your computer and then check your PYTHONPATH for this directory location.
To print the Python search path enter the following in the Python shell:
import sys
print sys.path
If the directory containing your library is missing you can try adding it interactively with
sys.path.append('/your/dir/here')
and try
import sqlite3
again. If this works you have to add this directory permanently to your PYTHONPATH environment variable.
PS: If the library is missing you should (re-)install the module.
import sqlite3
sqlite3 - DB-API 2.0 interface for SQLite databases.
You are missing the .so (shared object) - probably an installation step. In my Linux python installation, _sqlite3 is at:
${somewhere}/lib/python2.6/lib-dynload/_sqlite3.so
Python 2.6 detects where the sqlite3 development headers are installed, and will silently skip building _sqlite3 if it is not available. If you are building from source, install sqlite3 including development headers. In my case, sudo yum install sqlite-devel sorted this out on a CentOS 4.7. Then, rebuild Python from source code.
Try this:
from pysqlite2 import dbapi2 as sqlite
On my system _sqlite3.so located at:
'/usr/lib/python2.6/lib-dynload/_sqlite3.so'
Check that the directory is in your sys.path:
>>> import sys; print(filter(lambda p: 'lib-dynload' in p, sys.path))
['/usr/lib/python2.6/lib-dynload']
Does that fix your problem?
Python 2.5.4 (r254:67916, May 31 2009, 16:56:01)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sqlite
>>> import sqlite3
>>>
The 2.5.5. Mac port of Python 2.5 now has this hint:
"py25-sqlite3 #2.5.4 (python, databases)
This is a stub. sqlite3 is now built with python25"
And so an upgrade of the python25 port to python25 #2.5.5_0 made the import work again.
Since sqlite3 is among the dependencies of python25,
it is built anew when upgrading python25.
Thus,
$ sudo port upgrade python25
does the trick on Mac OS X, ports collection.
I face the same problem.
Steps to solve.
Download latest sqlite3 from sqlite website. sqlite-autoconf*
Install that in 3 simple steps
./configure
make
make install
Rebuild the python
make
make install

Categories