AttributeError:'module' object has no attribute 'call' :Python - python

I am new to python and not knowing whats going on here. I have tried searching a lot but had to end up asking here
I am trying to learn subprocess which executes a simple command as:
import subprocess
subprocess.call(['ls'])
Now, when I run the program I get this error:
Traceback (most recent call last):
File "subprocess.py", line 1, in <module>
import subprocess
File "/task/subprocess.py", line 2, in <module>
subprocess.call(['ls'])
AttributeError: 'module' object has no attribute 'call'

You called your file subprocess.py, change then name and you will be ok. You are trying to import from your file and not the module

ldap-new:~ # rm -rf subprocess.pyc
This worked for me i just removed .pyc file and run again
Regards,
-Mansur

Related

Python 2.7 & emulambda

Just installed emulambda today, using the command:
pip install git+https://github.com/fugue/emulambda.git
and created a simple python file test.py:
from __future__ import print_function
def lambda_handler(event, context):
print("Hello world")
when I try and run this with the command
emulambda test.lambda_handler test-event.json
I get the errors
Oops! There was a problem finding your function.
Traceback (most recent call last):
File "/usr/local/bin/emulambda", line 5, in <module>
emulambda.main()
File "/usr/local/lib/python2.7/dist-packages/emulambda/__init__.py", line 37, in main
lfunc = import_lambda(args.lambdapath)
File "/usr/local/lib/python2.7/dist-packages/emulambda/__init__.py", line 121, in import_lambda
raise e
AttributeError: 'module' object has no attribute 'lambda_handler'
I'm running python 2.7.12 - can anyone suggest what the problem is?
You called your module test.py, which is a conflict with the internal Python regression test module when you attempt to do the following:
emulambda test.lambda_handler test-event.json
Rename your file to something else like simon_test.py and try it again with:
emulambda simon_test.lambda_handler test-event.json

TypeError: 'module' object is not callable using cx_freeze

I've frozen my app with cx_Freeze and when running the .exe I get this error (only error):
C:\Python34\build\exe.win32-3.4>run.exe
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27
, in <module>
exec(code, m.__dict__)
File "run.py", line 18, in <module>
File "C:\Python34\Socket.py", line 5, in openSocket
s = socket.socket()
TypeError: 'module' object is not callable
If I run my app in Python then it works perfectly fine.I have done import socket in both the main python file (run.py) and the one mentioned in the error above (Socket.py)
How do I fix this?
Try renaming your "Socket.py" file to something else ("socket_maker.py"). Then delete all *.pyc files from the current directory (especially anything called socket.pyc).
I'm thinking that the module name you are trying to import is conflicting with the object and function names.

ImportError: cannot import name pynestkernel

So I spend last night trying to install nest (and pynest) to use with PyNN, and I am currently stuck. When I try to import nest I get:
>>> import nest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nest/__init__.py", line 52, in <module>
from . import pynestkernel as _kernel
ImportError: cannot import name pynestkernel
However, when I make the make installcheck it passes all the pynest tests.
I am using OS x Yosemite, and I did a new install of python 2.7.9 using macport.
Tried:
easy_install python-nest
Now I am getting a new error.
Getting:
>>> import pyNN.nest as sim
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pyNN.nest as sim
File "/Library/Python/2.7/site-packages/pyNN/nest/__init__.py", line 13, in <module>
from pyNN.nest import simulator
File "/Library/Python/2.7/site-packages/pyNN/nest/simulator.py", line 500, in <module>
state = _State() # a Singleton, so only a single instance ever exists
File "/Library/Python/2.7/site-packages/pyNN/nest/simulator.py", line 60, in __init__
self._cache_num_processes = nest.GetKernelStatus()['num_processes'] # avoids blocking if only some nodes call num_processes
AttributeError: 'module' object has no attribute 'GetKernelStatus'
Try using setuptools to install nest with easy_install python-nest.
I am trying something similar, with the further goal of having it working with python 3. So far I used the following commands:
git clone https://github.com/nest/nest-simulator.git
cd nest-simulator
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/nest -DPYTHON_EXECUTABLE=/usr/local/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m -DPYTHON_LIBRARY=/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib .
make
make install
which runs without errors and I can happily run nest. Iam still having troubles running pyNN (see https://laurentperrinet.github.io/sciblog/posts/2016-06-01-compiling-and-using-pynn-%2B-nest-%2B-python3.html)

python AttributeError:'NoneType' object has no attribute 'vtkPVPythonModule' paraview

I'm developing a CAD application with paraview using python ProgrammableFilter, everything works fine when I make import vtk but if I try from paraview.simple import ... I always get this error message:
Traceback (most recent call last):
File "<string>", line 22, in <module>
File "<string>", line 2, in RequestData
File "C:\Program Files (x86)\ParaView 4.1.0.32b\lib\paraview-4.1\site- packages\paraview\servermanager.py", line 2190, in find_module
if vtkPVPythonModule.HasModule(fullname):
AttributeError: 'NoneType' object has no attribute 'vtkPVPythonModule'
I though maybe if I set the PYTHONPATH it was going to work but nothing has changed.
You're not supposed to import paraview.simple in a ProgrammableFilter. You should never to that. The paraview.simple module is for client-side control scripting, while ProgrammableFilter is for data processing and executes on the 'server' (even when not connected to a remote server).

Trying to run pyexiv2

I'm trying to run a simple code to test that I have installed correctly pyexiv2 in my computer. I'm using python 2.6.6. on windows 7 64 bit
So I run this simple code:
import pyexiv2
print pyexiv2.exiv2_version_info
and I get this error:
Traceback (most recent call last):
File "C:/Users/Usuario/Desktop/pyexiv2/pyexiv2.py", line 1, in <module>
import pyexiv2
File "C:\Users\Usuario\Desktop\pyexiv2\pyexiv2.py", line 3, in <module>
print pyexiv2.version_info
AttributeError: 'module' object has no attribute 'version_info'
How can I fix that? Thank you
You named your own file pyexiv2.py as well; rename it or delete it, as it is being imported instead of the installed module.

Categories