AttributeError of threading.Thread in Python 2.7.5 - python-2.7

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!

Related

AttributeError: 'HTTPMessage' object has no attribute 'getparam'

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

python ImportError: No module named cy_unity graphlab

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

ImportError: No module named if trying to execute from command line

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

Nonetype not callable from joblib when requiring (but not using) cv2

This error is quite strange, whenever I use Kmeans of sklearn with n_jobs > 1 in a unittest and while requiring cv2 using setuptools results in a None being called by joblib.
A minimal failing example:
setup.py:
from setuptools import setup
setup(
name = "libbla",
# Removing "cv2" resolves the issue :S
install_requires = ["numpy", "scikit-learn", "cv2"],
test_suite = 'tests'
)
tests/some_test.py:
from sklearn.cluster import KMeans
# also fails without importing sklearn and cv2, just want them for the version numbers.
import unittest, numpy, sklearn, cv2
print("cv2", cv2.__version__)
print("np", numpy.__version__)
print("skl", sklearn.__version__)
class TestFeatureCreator(unittest.TestCase):
def test_kmeans_2_features(self):
KMeans(n_clusters = 2, n_jobs = 4).fit_predict(numpy.random.randn(360000, 3))
tests/__init__.py is empty.
Then whenever I run python2.7 setup.py test, I get the following output:
$ python2.7 setup.py test
running test
Searching for cv2
Best match: cv2 1.0
Processing cv2-1.0-py2.7.egg
Using /home/herbert/Spyder/bla/.eggs/cv2-1.0-py2.7.egg
running egg_info
writing requirements to libbla.egg-info/requires.txt
writing libbla.egg-info/PKG-INFO
writing top-level names to libbla.egg-info/top_level.txt
writing dependency_links to libbla.egg-info/dependency_links.txt
reading manifest file 'libbla.egg-info/SOURCES.txt'
writing manifest file 'libbla.egg-info/SOURCES.txt'
running build_ext
('cv2', '3.0.0-dev')
('np', '1.10.1')
('skl', '0.16.1')
test_kmeans_2_features (tests.some_test.TestFeatureCreator) ... ok
----------------------------------------------------------------------
Ran 1 test in 1.156s
OK
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.7/dist-packages/joblib/pool.py", line 535, in <lambda>
atexit.register(lambda: delete_folder(pool_folder))
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.7/dist-packages/joblib/pool.py", line 535, in <lambda>
atexit.register(lambda: delete_folder(pool_folder))
TypeError: 'NoneType' object is not callable
$
I'm not sure whether this is a opencv2, sklearn or numpy bug, which is why I went here. Would anyone know what happens here?
Some peculiarities:
removing "cv2" from install_requires removes both errors
idem for not running Kmeans
idem for Kmeans with no n_jobs supplied.
when printing atexit.register, delete_folder and pool_folder just before the error, none of them is None.
Please also comment when you can't reproduce the error :)
A fix for this issue has been merged in joblib master (to be included in the next release 0.10):
https://github.com/joblib/joblib/pull/329

Boto and Python on AWS

I am trying to get boto to work, but I am getting an error.
Installed boto via easy_install, or simply python ./setup.py install
cat boto.py
#!/usr/bin/python
import boto
conn = boto.connect_ec2()
3c075474c10b% ./boto.py
Traceback (most recent call last):
File "./boto.py", line 2, in <module>
import boto
File "/Users/vasiliyb/scripts/boto.py", line 3, in <module>
conn = boto.connect_ec2()
AttributeError: 'module' object has no attribute 'connect_ec2'
Just change the name of your module from "boto.py" to "myboto.py" (or whatever you like) and it will magically work.
You are basically redefining "boto" by naming your module boto.py.