I use python3 version in Ubuntu.
The code I use could run in python 2.7 version.
But I got some of Import Errors and Attribute Errors in python 3.
I want to edit this code for 3.6 version.
But I can't find any document for Attribute Error trouble shooting.
The error message I got is as below :
taylor#taylor-Rev-1-0:~/taylor/pyBook/ch2$ python parse_image.py
Traceback (most recent call last):
File "parse_image.py", line 35, in <module>
main()
File "parse_image.py", line 28, in main
charset = f.info().getparam('charset')
AttributeError: 'HTTPMessage' object has no attribute 'getparam'
and the methods or classes I imported is shown as below :
from urllib.request import urlopen
from html.parser import HTMLParser
charset = response.headers.get_content_charset()
you can use this in python3
Related
I cannot import mysql.connector in python 2.7.12. I cannot upgrade my python version, because some other servers are running on it.
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\mysql\connector\__init__.py", line 53, in <module>
from .connection import MySQLConnection
File "C:\Python27\lib\site-packages\mysql\connector\connection.py", line 518
f"This connection is using {tls_version} which is now "
^
SyntaxError: invalid syntax
This is the error I am getting even though I installed mysql-connector-python. Can someone please help me with this?
As I stated in my comment, you're most likely using a more recent mysql-connector-python.
From the list of version in PyPI, this might be the last one that supports 2.7:
https://pypi.org/project/mysql-connector-python/8.0.23/
This docs discusses that 2.7 was removed in 8.0.24:
installing cryptography:
successfully installed gcc, libffi-devel on python 2.7.
When i try executing the script getting the below error:
from cryptography.fernet import Fernet
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python2.7/site-packages/cryptography-2.4.2-py2.7-linux-x86_64.egg/cryptography/fernet.py", line 17, in
from cryptography.hazmat.primitives import hashes, padding
File "/usr/lib64/python2.7/site-packages/cryptography-2.4.2-py2.7-linux-x86_64.egg/cryptography/hazmat/primitives/padding.py", line 13, in
from cryptography.hazmat.bindings._padding import lib
AttributeError: _init_cffi_1_0_external_module
I am new to python and I am trying to work on a project with deep learning and want to use graphlab library. I use sublime text for coding on windows 10. My code is only this line:
import graphlab
I get this error msg:
Traceback (most recent call last):
File "test.py", line 1, in
import graphlab
File "graphlab__init__.py", line 59, in
from graphlab.data_structures.sgraph import Vertex, Edge
File "graphlab\data_structures__init__.py", line 25, in
from . import sframe
File "graphlab\data_structures\sframe.py", line 19, in
from ..connect import main as glconnect
File "graphlab\connect\main.py", line 26, in
from ..cython.cy_unity import UnityGlobalProxy
ImportError: No module named cy_unity
Try using graphlab.get_dependencies() in your interpreter.
I think I made a mistake when installing, i re-installed and it worked fine. Thanks anyway
I am getting following error
D:\pythongui>C:\Python27\python.exe D:/pythongui/controller/MainController.py
Traceback (most recent call last):
File "D:/pythongui/controller/MainController.py", line 5, in <module>
from view.MainView import Launcher
ImportError: No module named view.MainView
when I am executing the following command in terminal
C:\Python27\python.exe D:/pythongui/controller/MainController.py
But the same code is working in pycharm without any error.
My Directory structure is as follows :
I have tried following code
import GetMyIp as getMyIP
import sys
sys.path.append("view/MainView")
import Server as server
import view.MainView
When I run the following code, I got an AttributeError:
#!/usr/bin/env python
import threading
import time
def worker():
for i in range(10):
time.sleep(1) # Seconds
print i
threading.Thread(target=worker).start()
Error:
Traceback (most recent call last):
File "/home/yaa110/workspace/Python27/src/threading.py", line 3, in <module>
import threading
File "/home/yaa110/workspace/Python27/src/threading.py", line 11, in <module>
threading.Thread(target=worker).start()
AttributeError: 'module' object has no attribute 'Thread'
I run Python 2.7.5 on Ubuntu 13.10.
Moreover when I use python via terminal, then I got no Error by inputing codes line by line.
It looks like you've created a python file, or module in the current directory of this script which is titled threading or threading.py. This causes your import threading to import the wrong threading library; one where there is no Module named Thread in it!
Rename it and all should be ok. Running the script on my 2.7.2 worked just fine!