PyUnicodeUCS2_* error while importing VTK - python

I've run into a strange problem.
I built VTK with python wrappings on cent os 6.5.
On importing vtk it gives me PyUnicodeUCS2_* error. I checked python used for the build for unicode setting with sys.maxunicode. It is UCS4. I searched for this error and found that the error occurs when the VTK is built using UCS2 python. But, This is not the case in my case. What could be the reason for error?
The python that I'm using is picked from some other machine . If I run maxunicode on original previous machine it shows USC2. The same python (I copied the whole folder python2.6) on the other machine where I'm building VTK, shows maxunicode as UCS4. I think this has something to do with the problem.
Please help.

This error is caused by using an extension built by a UCS2-based Python interpreter with a UCS4-based interpreter (or vice-versus).
If you built it using the same Python interpreter then something is confusing in your build environment.

I tried to compile VTK with my python build several times. Checked the various paths in CMAKE to avoid conflict with system python. Still couldn't get rid of the error. Finally, I built the python with --enable-unicoe=ucs2. That solved the problem. Thanks for the help though.

Related

importing dlls with pythonnet in spyder

I have a python package that acts like a wrapper for a .dll written in C#. The binary is imported into python by the pythonnet package. Thus, the user can access the functionality of the so called cs_backend.dll conveniently from the python side. The import looks as follows:
import clr as __clr
import System as __System
__clr.AddReference(PATH_TO_CS_BACKEND + "\\cs_backend")
import cs_backend as __csb # exception thrown here
However, it seems that python can't import the .dll as I get a ModuleNotFoundError: No module named 'cs_backend'.
The odd thing is that this error only occures when running the code from Spyder. Executing exactly the same code from Visual Studio Code works perfectly fine.
Do you have any idea what the problem could be?
system specifications
os: windows 10
.net framework v4.5.1
python 3.8.5
spyder 4.2.1
Edit:
I have found a github issue on the pythonnet repository that describes a similar (although not quite the same) problem. However, since it has been open for about 3 years, it seems that there is little to no progress on that.
Edit 2:
There is a similar question here on stack overflow. The solution was to install a newer .NET Framework. This is not my problem since with any IDE other than Spyder the code works just fine. Thus, I guess that this is mainly a Spyder issue.
Currently, it seems that there is neither a solution nor an effort to resolve this problem.
It looks like the problem is caused by the IPython console integrated in Spyder.
A simple workaround is to execute the python script from the system console.
In Spyder this can be done by going to Run - Configuration per file - Execute in external system console.
With the new configuration it is at least possible to run the script.

Numpy installed, but module not found

I've tried several fixes for this suggested in other threads, but no luck.
I'm new to Python. I had 3.8.5 installed and wrote a few simple scripts that worked using PyCharm and the numpy and sympy modules. Today I opened PyCharm and tried to write a simple script using numpy, but I got an error saying the numpy module did not exist. I also got this error when trying to run the older scripts. I checked in cmd with pip3, and got the result that it was already satisfied. I uninstalled Python, numpy, and PyCharm, reinstalled all and I'm having the same problem. This problem seemed to crop up on its own - I don't recall making any changes that would've caused this.
Can anyone give me other options?
One of the most common issues with Python is having multiple versions installed and losing track of which one you are using and/or which one you're installing to with pip.
In Pycharm check what interpreter your project is using. If there is more than one available chance are you installed numpy on the other one.
https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add-existing-interpreter
You can also install numpy direct from Pycharm, simply hover over the import statement and if it's not installed on the current interpreter it will offer you a link to click in install it.
If that doesn't help, post the exact error message and your code.

How to fix this error on tabula.read_pdf() function in Python

I am trying to extract tables from a PDF file using Python (Pycharm).
I tried the following code:
from tabula import wrapper
object = wrapper.read_pdf("C:/Users/Ojasvi/Desktop/sample.pdf")
However, the error i got was:
"tabula.errors.JavaNotFoundError: `java` command is not found from this Python process. Please ensure Java is installed and PATH is set for `java`"
You probably need to add java to your system path. You can check those posts, they should help you in solving your problem:
How to Set Java Path On Windows?
Environment variables for java installation
I had every thing setup Java installed and Java path setup but was still getting same error, after spending half a day , I did below and everything worked.
I was using a python environment and running Tabula in python environment. I was getting error mentioned in questions.
I changed my python environment basically default one which is no environment and everything worked. I think Tabula is not able to detect Java once we are inside an python environment.

"R6034 An application has made an attempt to load the C runtime library incorrectly" after pygtk being installed

I'm using python 2.7.9 and encountered a problem when installing pygtk.
It displayed "Runtime error!...R6034 An application has made an attempt to load the C runtime library incorrectly" when installing numpy/scipy after pygtk being installed.
I tried to figure it out by searching it in stackoverflow and found two similar questions: Runtime error R6034 in embedded Python application and An application has made an attempt to load the C runtime library incorrectly.
So following the first one, I deleted the path corresponding to msvcr90.dll, however, it still cannot work. Then I chose to simply delete msvcr90.dll; at this time, this error wasn't presented when installing numpy/scipy, however, these two modules cannot work when simply typing "importing numpy/scipy".
I also renamed gtk-2.0 following the second one. Then numpy and scipy can be successfully installed. But it displayed "Error processing line 3 of C:\Python27\lib\site-packages\pygtk.pth" when installing matplotlib using pip.
I'm really confused about it. Can anybody provide some methods to fix it?
I've installed Python and PyGTK on 5+ machines, at least two of them brand new, clean builds of Win 7.
I've got the An application has made an attempt to load the C runtime library incorrectly error whenever I install a Python package as a windows installer (rather than using pip) on all these machines. It's annoying, but has never made a jot of difference, both Python and Gtk function correctly.
You've deleted msvcr90.dll, and that is why you get your Error processing line 3... If you look at this file, you'll see that line 3 is import runtime, and if you look further into the 'runtime' package, you'll see that this then tries to find the missing dll.
I think your best bet is to try to restore the missing file. If it's still in your recycle bin - great!
If not, the best thing to do is reinstall the Visual C++ runtime library
I made this video to show my way: https://www.youtube.com/watch?v=s6jhR1VBfeU. I use Anaconda to embedded Python in my C++ application. I simply changed "msvcr90.dll" to "msvcr90.dll_hihi" in 3 folders:
C:\Users\your user\Anaconda2\Library\bin, C:\Users\your user\Anaconda2 and C:\Program Files\Intel\iCLS Client (for x64)

An UCS2-UCS4 incompatibility import failure of a Cythnized pure-Python module

I'm running into a cython-unicode problem which I hope you can help me with -
I'm trying to compile with cython a python module which works alot with unicode objects.
I'm working on Ubuntu 12.04 32bit, (on a VM on a Win7 64bit host if it has any importance), I'm using Py2.5.4 (can't change that) which I've installed side-by-side with the provided Py2.7.3 (and soft-linked /usr/bin/python to /usr/bin/python2.5), and Cython 19.02 (current one). I'm compiling with no special flags.
Now, as compiling goes seemingly OK, when I open a Py (same 2.5.4) and try to import the resulting. SO file, I get a PyUnicodeUCS2 type error. That is supposed to mean, as I understand, that the SO was compiled on a python configured with UCS4, and imported to python configured with UCS2. But It's the same python I compiled on and imported to.
for compilation I use $ python setup.py bild_ext --inplace where setup.py uses distutlis.extension.Extension and Cython.Distutile.build_ext .
Can someone enlighten me with what's going on and what I can do with it?
I'll be happy to provide more details if I wasn't clear enough.
Thanks a lot..

Categories

Resources