I had the issue on Ubuntu (14.04) on AWS but resolved it by upgrading my Python to 3.4.3 (from 2.7). However, I still get the issue locally (Mac Yosemite, v10.10.5) even though Ive upgraded my python. The error is:
Traceback (most recent call last):
File "payment_app.py", line 97, in <module>
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'
My Python version (python3 --version) on my Mac is:
Python 3.4.4
Is there any differences between Mac:s version of Python and Ubuntu:s? If so, how to I handle this error?
Thanks in advance.
Peter
Related
I tried to run Python3 on my Windows but it gives me a AttributeError from io.py.
I have tried both the Windows Store version and Download from https://www.python.org/downloads/
When I try to run python3 or py in PowerShell 7.2.6 terminal I get
PS>python3
>Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
File "C:\Program\Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\io.py", line 87, in <module>
AttributeError: module 'abc' has no attribute 'ABCMeta'
or
PS>py
>Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
File "C:\Users\UserName\AppData\Local\Programs\Python\Python310\lib\io.py", line 87, in <module>
AttributeError: module 'abc' has no attribute 'ABCMeta'
With troubleshooting I have tried a few things
To reinstall both from the Windows Store and the Download from https://www.python.org/downloads/, but it doesn't seem to resolve the problem.
Only run the store version or the download from the website.
I have tried to troubleshoot on the internet, but I don't see anything when it comes to running Python alone. And usually comes down to naming Python scripts which I don't want to run specificly.
I thought it could be a systen PATH problem in Windows, but that seems to be not the case as it still didnt work after I changed the path to "C:\Users\UserName\AppData\Local\Programs\Python\Python310" and "C:\Users\UserName\AppData\Local\Programs\Python\Python310\Scripts".
And the problem seems to come from the io.py which can't see the attribute ABCMeta from the module abc.
How can I solve this problem?
I am currently trying to use GTK3 and Python3 for GUI development.
Everything is working fine while doing this on my Ubuntu device, but as I want to be able to have Windows executables later, I need to set these tools up on Windows 7.
I have Python 3.4.4 (64 Bit) installed on my system and tried solutions from other posts on Stackoverflow to be able to use GTK with it, but I was not able to get it to work.
When trying to import Gtk (import gi and from gi.repository import Gtk) on the Python shell, the following error occurs:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2158, in _find_spec
AttributeError: 'DynamicImporter' object has no attribute 'find_spec'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\gi\importer.py", line 100, in find_module
'introspection typelib not found' % namespace)
ImportError: cannot import name Gtk, introspection typelib not found
What I have installed at the moment:
PyGi 3.18.2 AIO for Python 3.4 64-bit
GTK3-Runtime Win64 (bin directory created during installation is included into PATH)
Which is the best way to get a working set of Python3 and GTK3 on Windows? (As far as I have seen it is not possible to create Windows executables using Ubuntu.)
You need only to install Python 3.4 and the PyGObject project on sourceforge (the one you mentioned in your post).
This setup must work on Windows, because it works for me.
Maybe you missed to check the Gtk3 libraries during installation of PyGObject (this is a frequent error).
You don't need msys2 at all to use PyGObject in Python.
Environment:
Ubuntu 10.04.4 LTS
Python 3.4.3
I have a working python 3.4 Flask HTTPS server running perfectly on Windows. I need to transfer this over to an existing Ubuntu 10.04.4 LTS server. I have built python 3.4 on there with no problems but when I run my web server it fails with the error:
Traceback (most recent call last):
File "./server.py", line 3, in <module>
from app import create_app
File "/opt/license-server/app/__init__.py", line 10, in <module>
from config import config
File "/opt/license-server/config.py", line 9, in <module>
class Config:
File "/opt/license-server/config.py", line 25, in Config
LDAP_TLS_VERSION = ssl.PROTOCOL_TLSv1_2
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'
I did some digging around on Windows using pyCharm to find out what is going on and it seems that PROTOCOL_TLSv1_2 is defined in _ssl.py which I believe comes from _ssl.pyd. Neither _ssl.py or _ssl.pyd exists on the Ubuntu python install which leads me to believe that I'm missing some option or something when compiling but I cannot find any reference to this on the python web site on what is missing or how to get the TLS-1.2 stuff.
Can anyone point me in the right direction please?
When you build your Python 3.4 from sources, at the end of the build you get a report saying which modules were not built. My bet is that the ssl module was not build, because your Ubuntu installation doesn't have SSL packages installed. Try:
sudo apt-get install libssl-dev openssl
then try to rebuild your Python 3.4 and see if the SSL module is built.
I am trying to get Cherrypy to output json for a project and on my Mac adding the #cherrpy.tools.json_out() decorator is working a treat but on my Ubuntu 13.04 system I get this error.
Traceback (most recent call last):
File "cherrypy.py", line 1, in <module>
import cherrypy
File "/bla/cherrypy.py", line 4, in <module>
class Root(object):
File "/bla/cherrypy.py", line 6, in Root
#cherrypy.tools.json_out()
AttributeError: 'module' object has no attribute 'tools'
The code above is a direct copy from the bottom of this page.
http://tools.cherrypy.org/wiki/JSON
If i enter a python shell then run interactive help on the module I get a similar result.
help> cherrypy
problem in cherrypy - <type 'exceptions.AttributeError'>: 'module' object has no attribute 'tools'
I have tried searching but I can't find anyone else having the same issue? (Maybe I am missing the wood for the trees?)
I have tried reinstalling the package through apt and manually from the cherrypy source all against Python 2.7
Although I am developing on Mac and Ubuntu I will be deploying on an Ubuntu server so I would like to sort this out sooner rather than later.
Your help is much appreciated
Do you use python-cherrypy from ubuntu package? It's version is 2.3.0 which does not have cherrypy.tools modules.
Install newer version (sudo pip install -U cherrypy).
I've been tearing my hair out and trying the solutions to getting Python and MySQL to play nicely with 64-bit architecture, and the solution seems to have all components installed/run as 32-bit.
My issue is that for some reason, running Python in 32-bit mode via
$ arch -i386 /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
and then
import MySQLdb
gives me
import MySQLdb
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named MySQLdb
However, when I run python in 64-bit mode and trying 'import MySQLdb' I get the dreaded:
import MySQLdb
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/init.py", line 19, in
File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 7, in
File "build/bdist.macosx-10.6-intel/egg/_mysql.py", line 6, in bootstrap
ImportError: dlopen(/Users/me/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): no suitable image found. Did find:
/Users/me/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so: mach-o, but wrong architecture
So my question is, why can't Python find the module in 32-bit mode? the "wrong architecture" error leads me to believe that MySQL-python is installed as 32-bit, so I don't think it's that 32-bit Python can't "see" the module. I have both the python and the .python-eggs path on my $PATH in .bash_profile, so what am I missing here?
Not exactly an answer, but have you tried just to pip install MySQL-python? If you have some mysql_config in your path, it should compile just fine.
– I am using a Python 2.7.2 via homebrew, a MAMP 2.0 installation, running on 10.6. with a 64bit kernel.