I will work with mysql, but it gives this error anyway. I did delete the module but it did not change, I loaded it differently, I could not solve the modules.
Traceback (most recent call last):
File "C:\Users\INAL\Desktop\Son Scriptler\mysql\mysql.py", line 1, in <module>
import mysql.connector
File "C:\Users\INAL\Desktop\Son Scriptler\mysql\mysql.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package
You might not have the mysql-connector did you try installing it using pip?
pip3 install mysql-connector
The problem was that my project name was mysql.py and I solved the problem by changing the project name.
Related
I want to use json parser in my python script.
When I import json module there is an ImportError:
root#msc-nr-imx6x:~# python3
Python 3.5.2 (default, Aug 9 2017, 22:59:34)
[GCC 6.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'json'
>>>
I supposed that in python3 json is built-in.
Python is running on - arm imx6, yocto 2.2, python 3.5.2
So how can I install json module?
Thank you
Edit - add output of test.py script:
try:
import json
except ImportError:
import simplejson as json
output:
root#msc-nr-imx6x:~# python3 test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
import json
ImportError: No module named 'json'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 4, in <module>
import simplejson as json
ImportError: No module named 'simplejson'
Yocto creates embedded systems: this is why python does not automatically come with all of the modules it usually does. Whoever created the image you're using had the option of including all standard modules but did not do that.
If you are building your own image you can include more python packages in your image install, either python3-json for just what you need or something like python3-modules to get all the common ones: see meta/recipes-devtools/python/python3/python3-manifest.json for more details on the split.
EDIT: Actually, you are using an old Yocto version so probably want to look at meta/recipes-devtools/python/python-3.5-manifest.inc for the details
In your case you can try this code snippet:
try:
import json
except ImportError:
import simplejson as json
you can visit python json module import error
I am on Mac OS Mojave
I am not able to read table data from local (in my machine) MySQL DB using Python3.7
Very new to python, so I downloaded Python3.7 then pip install mysql connector.
But when I import mysql.connector in the script I keep getting errors
I did the same pip install in the server running ubuntu and I was able to fetch data. Follow the same process in Mac and it does not work.
If I run import mysql.connector from IDLE and run the same file, it runs just fine.
But when I run the file through terminal it give me an error.
I have so far added/updated env to include mysql connector.
I am not sure what can I really do here
Looking for some help
Traceback (most recent call last):
File "compare_vion_csc_with_cmdb.py", line 1, in <module>
import mysql.connector
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/__init__.py", line 42, in <module>
from .connection import MySQLConnection
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/connection.py", line 50, in <module>
from .network import MySQLUnixSocket, MySQLTCPSocket
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/network.py", line 33, in <module>
import socket
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 52, in <module>
import os, sys, io, selectors
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 12, in <module>
import select
File "/Users/skarki/Desktop/Python/Scripts/select.py", line 3, in <module>
mydb = mysql.connector.connect(
AttributeError: module 'mysql' has no attribute 'connector'
My bash_profile is set to the following:
export PATH=/Users/nimam/jython2.7.0/bin:/opt/local/bin:/opt/local/sbin::/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I need to include jython as I am running the swinglibrary for the robotframework, but I would like to include ImageHorizonLibrary as well. However, i am currently not able to run the ImageHorizonLibrary. I get the following error.
[ ERROR ] Error in file '/Users/nimam/swinglibrary-demo/read_attributes.robot': Importing test library 'ImageHorizonLibrary' failed: ImportError: No module named ImageHorizonLibrary
Traceback (most recent call last):
None
PYTHONPATH:
/Users/nimam/jython2.7.0/bin
/Users/nimam/jython2.7.0/Lib
__classpath__
__pyclasspath__/
/Users/nimam/jython2.7.0/Lib/site-packages
CLASSPATH:
/Users/nimam/jython2.7.0/jython.jar
Rotarran-2.0.8-standalone.jar
If I comment out the export PATH in the bash_profile, it recognizes the ImageHorizonLibrary but not the SwingLibrary. I get the following error:
[ ERROR ] Error in file '/Users/nimam/swinglibrary-demo/read_attributes.robot': Importing test library 'SwingLibrary' failed: ImportError: No module named SwingLibrary
Traceback (most recent call last):
None
PYTHONPATH:
/usr/local/bin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Users/nimam/Library/Python/2.7/lib/python/site-packages
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
I have a feeling I can solve this by playing around with the virtualenv. Please let me know if there is a way I can run both libraries at the same time.
I installed the following mysql connector via pip:
pip install --allow-external mysql-connector-python mysql-connector-python
In my code I simply do a import mysql.connector as Connector and everything works fine. However, I used to use Python 2.7.X and now want to switch to Python 3.X (currently 3.5).
When I run my stuff under 2.7.X everything works fine. However, starting the same script with python 3.5 I get the following error message:
Traceback (most recent call last):
File "SWCrawler3.py", line 3, in <module>
import Configuration as cfg
File "/Users/Tom/SW/SWCrawler/SWCrawler/Configuration.py", line 4, in <module>
from database.MySQLConnection import MySQLConnection as MySQLConn
File "/Users/Tom/SW/SWCrawler/SWCrawler/database/MySQLConnection.py", line 6, in <module>
import mysql.connector as Connector
File "../mysql/connector/__init__.py", line 33, in <module>
from mysql.connector.connection import MySQLConnection
File "../mysql/connector/connection.py", line 128
except Exception, err:
^
SyntaxError: invalid syntax
Please note, that I wrote a wrapper file that I call MySQLConnection.
I had to intall the python3 packages of mysql-connector-python.
On my Mac I did the following:
brew install python3
pip3 install --allow-external mysql-connector-python mysql-connector-python
After that is worked. So use pip3.
On Windows with Python 3.5, I did something very close to toom's answer, that is :
pip3.5 install --allow-external mysql-connector-python mysql-connector-python
i'm trying to install kitsune in the ubuntu terminal. I am not able to initialize the database. When i give the command ./manage.py syncdb --migrate , i get the following error
Error: Tried importing 'settings_local.py' and 'settings.py' but neither could be found (or they're throwing an ImportError). Please come back and try again later.Traceback (most recent call last):
File "./manage.py", line 30, in <module>
from kitsune import settings # Assumed to be in the same directory.
File "/home/user/kitsune/kitsune/settings.py", line 740, in <module>
import djcelery
File "/usr/local/lib/python2.7/dist-packages/djcelery/__init__.py", line 22, in <module>
from celery import current_app as celery # noqa
File "/usr/local/lib/python2.7/dist-packages/celery/five.py", line 307, in __getattr__
module = __import__(self._object_origins[name], None, None, [name])
File "/usr/local/lib/python2.7/dist-packages/celery/_state.py", line 20, in <module>
from celery.utils.threads import LocalStack
File "/usr/local/lib/python2.7/dist-packages/celery/utils/__init__.py", line 24, in
<module>
from celery.exceptions import CPendingDeprecationWarning, CDeprecationWarning
File "/usr/local/lib/python2.7/dist-packages/celery/exceptions.py", line 13, in <module>
from billiard.exceptions import ( # noqa
ImportError: No module named exceptions
I can't find the exceptions file in billiard. How do I fix this error?
I had this error with fabric. The error message was the same:
ImportError: No module named exceptions
It turned out to be my fabric was out of date. The error was resolved by upgrading fabric to the latest version (1.10) with:
$ sudo pip install fabric --upgrade
For your information, I am running Ubuntu 12.04 64-bit with Python 2.7.3
Exceptions should be a python file in a directory called billiard, for example, you create a file called exceptions.py and add the classes and methods that you need .. this can work around the problem.
You should follow kitsune installation process described in http://kitsune.readthedocs.org/en/latest/hacking_howto.html
There is a link to separate chapter on vendor-packages http://kitsune.readthedocs.org/en/latest/vendor.html#vendor-chapter. You should install all the vendor packages needed by kitsune including billiard and celery (your errors).