I am unable to use spawnlp in python 2.7.2 - python

I am playing around with entangled which makes use of os.spawnlp. I am currently running Python 2.7.2.
Here's the error I am getting.
Traceback (most recent call last): File "create_network.py", line
47, in
nodes.append(os.spawnlp(os.P_NOWAIT, 'python', 'python py', str(startPort))) AttributeError: 'module' object has no attribute
'spawnlp'
How do I go about solving this issue? There doesn't seem to be any indication that spawnlp was removed/deleted since it was first added in version 1.6.
I've already re-downloaded the windows python installer and ran it with the repair option. The only thing I can think it might be is that this computer is 64bit and the python version is 32bit... I don't think that's the problem but that's the only thing I can think of...
Lastly, its recommended to use the subprocess module rather than the os.spawn*

In the python documentation it states that
spawnlp(), spawnlpe(), spawnvp() and spawnvpe() are not available on Windows. spawnle() and spawnve() are not thread-safe on Windows; we advise you to use the subprocess module instead
You have to indeed use another module to create subprocesses.

Related

pyFirmata gives error: module 'inspect' has no attribute 'getargspec'

I'm trying to use pyFirmata, but I can't get it to work. Even the most basic of the library does not work. I guess there is something wrong with the library code.
from pyfirmata import Arduino,util
import time
port = 'COM5'
board = Arduino(port)
I get this error:
Traceback (most recent call last):
File "c:\Users\Public\pythonpublic\arduino.py", line 5, in <module>
board = Arduino(port)
^^^^^^^^^^^^^
File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\__init__.py", line 19, in __init__
super(Arduino, self).__init__(*args, **kwargs)
File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 101, in __init__
self.setup_layout(layout)
File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 157, in setup_layout
self._set_default_handlers()
File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 161, in _set_default_handlers
self.add_cmd_handler(ANALOG_MESSAGE, self._handle_analog_message)
File "C:\Users\marce\AppData\Roaming\Python\Python311\site-packages\pyfirmata\pyfirmata.py", line 185, in add_cmd_handler
len_args = len(inspect.getargspec(func)[0])
^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?
As already pointed out in another answer, the pyFirmata modules is currently documented to run on Python 2.7, 3.6 and 3.7. This doesn't mean it won't work on other versions, but probably that it hasn't been tested on other versions by the author and it isn't officially supported. So it may or may not work on newer Python versions.
Your error message is caused by a missing function inspect.getargspec(). This function is part of the Python Standard Library, but has been deprecated since Python 3.0 (which came out in 2008). Unfortunately the author wasn't aware of this or simply didn't bother to fix it, so now the code doesn't work anymore with the latest version of Python.
In the Python documentation, you can see that the function is still available in version 3.10, but not in version 3.11.
To solve this you have a number of options:
Downgrade to Python 3.10, which is currently still a good option (Python 3.10 is "alive" until 2026-10-04). I don't know if all other functionality does work. I guess it will, but you would have to find out yourself.
Downgrade to Python 3.7, which is claimed to be supported. Given that Python 3.7 is also still alive (until 2023-06-27), that's a reasonable option as well.
Create an issue for the pyFirmata module and hope the author will fix the problem. Note that an issue has already been created by someone in 2019 but apparently without effect. You could leave a comment there confirming that this has now broken for real.
Clone the library and fix it yourself (and create a Pull Request to get it in the official library).
Find another, similar, library that does work with Python 3.11.
Write the code yourself.
Downgrading to a Python version between 3.7 and 3.10 is certainly the simplest option, and leaving some feedback to the author will give you a chance it will be fixed in the future, in case your planning to use your script for a longer time.
According to the first line of pyFirmata docs:
It runs on Python 2.7, 3.6 and 3.7
You are using Python 3.11. The inspect (core library module) has changed since Python 3.7.

gdb.printing not available in python2

First of all, let me start out by saying, I am using gdb version 7.7 built --with-python
the python version is 2.6.x
And No I cannot upgrade them, since I'm limited by the devtools specifically meant for debugging my companies code.
There a lot of useful gdb-python scripts but all of them require me to
import gdb.printing
But I get an import error
(gdb)python import gdb.printing
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named printing
Error while executing Python code.
Is there any way to get the gdb.printing module in this version of gdb and python? (python3 works fine).
I would really appreciate any inputs for this.

How do I troubleshoot ipython-listener and/or gedit's ipython plugin?

I am running Gedit 3.8.3, Python 2.7.5+ and IPython 0.13.2 and the Gedit Ipython Plugin.
I know there are better IDEs for Python out there but this used to "just work" and then I got a new machine and installed Ubuntu 13.10 and it doesn't work anymore. The plugin used to give me an error, (gedit:23136): libpeas-WARNING **: Could not find loader 'python' for plugin 'ipython' but I followed some advice on AskUbuntu and edited the Loader line in /usr/lib/gedit/plugins/ipython.plugin to Loader=python3 and it now loads without error but also doens't do anything. Whether or not iPython-listener is running, the error I see in the console is
Traceback (most recent call last):
File "/usr/lib/gedit/plugins/ipython.py", line 98, in send_to_ipython
self.socket.sendto(code, (self.listener_host, self.listener_port) )
TypeError: 'str' does not support the buffer interface
Is there a way to get this working?
Reposting as an answer:
The gedit IPython plugin appears to be written for Python 2 only, but it looks like it only takes a small change to adapt it to Python 3. Find the line on which the error occurred:
self.socket.sendto(code, (self.listener_host, self.listener_port) )
And change it to this:
self.socket.sendto(code.encode('utf-8'), (self.listener_host, self.listener_port) )
UTF-8 should be the right default on most modern Linux systems.

pythons' select.poll() method on Apple OSX

I am currently using MAC OSX and realised that python's select.poll() is not supported.
I went through various discussions and realised that OSX python doesnot support poll() ,
and I then re-installed python using macports, changed $PATH and realised that select.poll()still returns the same error
Traceback (most recent call last):
File "server_poll.py", line 14, in
poll = select.poll()
AttributeError: 'module' object has no attribute 'poll'
turns out, even macports doesnot support poll() anymore.
So, I then installed homebrew and same was the case.
I can now run poll() only through the Ubuntu VM .
Just wanted to know if anyone here could use select.poll() through macports/homebrew or any other method??
I am learning /understanding event based programming(using python) and it would be great if I can run poll() or related methods , before I move onto twisted.
also is there a substitute method what I can use instead of poll() ? is it select.select()??

sys.path.append doesn't work with Python 3.x

I have Blender 2.66a which is an application that offers Python 3.3 APIs, On my system I have an installation of Python 3.2 with several modules that I wish to use inside Blender, I tried both
sys.path.append(r"/usr/lib/python3.2/")
sys.path.append("/usr/lib/python3.2/")
and this commands gives no errors, infact even the autocomplete feature works and new modules are indexed, so i tried
import tkinter
but this generates the following error
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "/usr/lib/python3.2/tkinter/__init__.py", line 42, in <module>
raise ImportError(str(msg) + ', please install the python-tk package')
ImportError: No module named '_tkinter', please install the python-tk package
and I don't get the point of this error because it fails to load a module that it's there asking me to install the same module because that module is not installed ( ? ).
What can cause this obscure problem ?
EDIT
the tkinter module works from the gnome-terminal
If I got you right, you're using Python 3.3 from Blender but try to include the 3.2 standard library. This is bound to give you a flurry of issues, you should not do that. Find another way. It's likely that Blender offers a way to use the 3.3 standard library (and that's 99% compatible with 3.2). Pure-Python third party library can, of course, be included by fiddling with sys.path.
The specific issue you're seeing now is likely caused by the version difference. As people have pointed out in the comments, Python 3.3 doesn't find the _tkinter extension module. Although it is present (as it works from Python 3.2), it is most likely in a .so file with an ABI tag that is incompatible with Blender's Python 3.3, hence it won't even look at it (much like a module.txt is not considered for import module). This is a good thing. Extension modules are highly version-specific, slight ABI mismatches (such as between 3.2 and 3.3, or two 3.3 compiled with different options) can cause pretty much any kind of error, from crashes to memory leaks to silent data corruption or even something completely different.
You can verify whether this is the case via import _tkinter; print(_tkinter.__file__) in the 3.2 shell. Alternatively, _tkinter may live in a different directory entirely. Adding that directory won't actually fix the real issue outlined above.

Categories