I had tested a web based application which uses Python (2.7.8) scripts to create a dynamic content.
I am parsing some XML data and performing several operations on it.
One of the operations requires searching certain type of data which uses the findall(xpath) function from ElementTree.
Now the place where I need to deploy is a Linux box which has an older version of Python (2.6.6).
I had some trouble due to the older ElementTree not having certain capabilities.
I followed this ElementTree SyntaxError: expected path separator ([). I copied the ElementTree from 2.7.8 to the new box and imported from there.
It imports fine but now I get a different error which is as follows:
Traceback (most recent call last):
File "./filename_python.py", line 117, in <module>
for ch in child.findall(xpath):
File "/usr/lib64/python2.6/xml/etree/ElementPath.py", line 293, in findall
return list(iterfind(elem, path, namespaces))
File "/usr/lib64/python2.6/xml/etree/ElementPath.py", line 194, in select
if "".join(e.itertext()) == value:
AttributeError: itertext
I cannot update the Python version on that box and I cannot add any modules so anything new has to be imported locally.
Any help is appreciated.
Thank you.
It doesn't seem to me that you've backported the 2.7.x version library properly. Take a look at the stack trace and you will see it is still referring to the library in your Python 2.6.x path:
/usr/lib64/python2.6/xml/etree/ElementPath.py
You could also consider lxml - you don't need to install it as a system library. Simply clone from the git repository here, and copy the code into your projects directory.
Related
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.
I'm unable to import pandas with import pandas as pd on replit.
I've already installed the package with pip install pandas and it can be seen in packages. I've successfully imported it to other projects on replit. Every time I try importing it into my code on this project, it gives me the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import pandas as pd
File "/home/runner/thing/venv/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/home/runner/thing/venv/bin/python"
* The NumPy version is: "1.22.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: libz.so.1: cannot open shared object file: No such file or directory
You don't need to use pip to install packages on repl.it -- and in fact, you shouldn't! Using Nix derivations not only works better (as you're using their OS distro the way it's designed), but also keeps their storage costs low, by allowing packages to be used from a read-only, hash-addressed, shared store.
Binaries built for other distributions might assume that there will be libraries in /lib, /usr/lib, or the like, but that's not how NixOS works: Libraries will be in a path like /nix/store/<hash>-<packagename>-<version>/lib, and those paths get embedded into the executables that use those libraries.
The easiest thing to do here is to create a new bash repl, but to add a Python interpreter to it. (I suggest this instead of using a Python repl because the way they have their Python REPLs set up adds a bunch of extra tools that need to be reconfigured; a bash repl keeps it simple).
Create a new bash repl.
Click on the three-dots menu.
Select "Show Hidden Files".
Open the file named replit.nix
Edit the file by adding a Python interpreter with pandas, as follows:
{ pkgs }: {
deps = [
pkgs.bashInteractive
(pkgs.python38.withPackages (p: [p.pandas]))
];
}
...changing that to taste (as long as they're getting software from a channel that has binaries for Python 3.9 or 3.10, for example, you can change python38 to python39 or python310).
Click the "run" button
In the new shell that opens, run python, and see that you can import pandas without trouble.
If, after you add a Python file to your repl, you can also change the .replit hidden file to make it run that file automatically on startup. Note that on NixOS, you should use #!/usr/bin/env python as your shebang, as PATH lookups are essential.
I am currently working on a Django project that necessitates the functionality of taking an InChI string and converting it into a molecule, but the package that I'm using seems to have an issue with its function MolFromInchi. Whenever I try to use this function, python tends to generate this traceback:
Ex.
>>> from rdkit.Chem.inchi import MolFromInchi
>>> mol = MolFromInchi('InChI=1S/O2Si/c1-3-2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\tcherry\repos\dataslate_django\venv\my-rdkit-env\lib\site-packages\rdkit\Chem\inchi.py", line 71, in MolFromInchi
mol, retcode, message, log = rdinchi.InchiToMol(inchi, sanitize, removeHs)
TypeError: No to_python (by-value) converter found for C++ type: class boost::shared_ptr<class RDKit::ROMol>
This error seems to be derived from the source code of the rdkit package, but I was wondering if there's anything that I can do to circumvent or mitigate this issue while still being able to incorporate the functionality of MolFromInchi into my project.
NOTE: I was able to reproduce this error after following the instructions on how to install RDKit with Conda posted on the RDKit Documentation, and this question pertains to the most current version of RDKit (2020.03.1).
It turns out that the reason I came across that issue is because whenever you make changes to the source code (which I've done to address a different issue with my project), those changes influence the .conda cache folder, meaning that if you were to ever uninstall and reinstall a conda package, the installation process would refer to the cache folder.
Trying to implement ytini (yt for Houdini) Python framework.
http://www.ytini.com/
Resolved most install erros but am still getting the following when I load a datfile
Not sure if this might be related to some configuration for ytini or if its more of a Python specific error.
Traceback (most recent call last): File "", line 14,
in File "/home/jim/.local/lib/python2.7/site-packages/yt/__init__.py", line 44,
in import yt.utilities.physical_constants as physical_constants
AttributeError: 'module' object has no attribute 'utilities
Can any Python experts suggest any troubleshooting steps?
Update>
If I simply do an import yt I get the following error
Warning! HDF5 library version mismatched error
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
'HDF5_DISABLE_VERSION_CHECK' environment variable is set to 1, application will
continue at your own risk.
Headers are 1.10.0, library is 1.8.11
This error means that you are treating yt.utilities as an object from which you are trying to access the object attribute physical constants, which is correct, but python thinks that this attribute doesn't exist. However, I am unable to reproduce this error and can access the values stored therein. What else is in your code? It looks like you are accessing another module function of yt which uses the constants attributes, is that correct? Also, are you using python 2.7 or 3.x?
In terms of installing package in 2 different places, I've had this happen before which was very frustrating, but the folders can be found by doing a folder search for the module name and should return all versions saved in different locations. The exact location of the modules varies with IDE, OS, weather...
I'm using Mountain Lion at the moment.
I've installed Blender (because it's a dependency of OpenGrasp), and downloaded OpenGrasp. However, I try to load the robot editor up and I get this:
$ python GraspRobotEditor.py
Traceback (most recent call last):
File "GraspRobotEditor.py", line 34, in <module>
import Blender
ImportError: No module named Blender
How do I point Python to the Blender python interface? the Getting Started guide doesn't instruct you much here.
(I'm sure this is a trivial problem to solve but I'd like to see this documented on StackOverflow anyway.)
From the error you it can't find the python module Blender which represents the python hook to Blender. So there could be a few This could be any number of reasons to do with your setup.
The first is that the Blender module is runtime generated whileBlender is running. The specific 'Blender' module used is part of the Blender 2.4x series. According to the link you provided there, they mention porting to newer versions but checking their snv the code is definitely written for 2.49.
Blender 2.49b was the last stable release - http://download.blender.org/release/ Ensure you are using that.
The next thing is whether it can be run via the the Run Script command
TL:DR
Start up blender
Switch to the text workspace
Open the script and see if it can be run directly.
If not you will need to install the folder to the Blender modules directory of your install and then try running it.
Edit: Was looking at into the SVN some more and there does appear to be a version 2 for blender 2.5+ which can be put into a zip file and installed via the add-on installer. According to the bl_info it was build for 2.58 but what support level you would need to try out yourself.