So I am having trouble compiling a very simple python script using JPype.
My code goes like:
from jpype import *
startJVM(getDefaultJVMPath(), "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()
and when I run it I receive an error saying:
Traceback (most recent call last): File "test.py", line 2, in
<module>
startJVM(getDefaultJVMPath(), "-ea") File "/usr/lib/pymodules/python2.7/jpype/_core.py", line 44, in startJVM
_jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error =
/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared
object file: No such file or directory at
src/native/common/include/jp_platform_linux.h:45
I'm stuck and I really need help. Thanks!
I had the same problem
RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error = /usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared object file: No such file or directory at src/native/common/include/jp_platform_linux.h:45
In my case wrong JAVA_HOME path was set
/profile/etc
export JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
PATH="$JAVA_HOME/bin:$PATH"
export PATH
The work around is to define the full path directly in the call to the JVM:
from jpype import *
startJVM('/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/MacOS/libjli.dylib', "-ea", "-Djava.class.path=/tmp/Jpype/sample")
java.lang.System.out.println("Hello World!!")
shutdownJVM()
Original text:
Similar issues when trying to run JPype on MacOS El Capitan. I could
not figure out how to coax the _darwin.py code finding the correct JVM
location, despite the JAVA_HOME system variable being set properly.
Caveat cursor, trying to run the above code in the Spyder IPython console did not produce any output, but the normal Console would.
Related
I have this Python code: https://github.com/andreagrandi/aoc_2019/tree/master/aoc
which runs perfectly from the terminal (Python 3 required) if I do for example: python aoc_03.py
But if I try to run it from VSCode, taking advantage of the Python extension and integration, I get this error:
(aoc) ➜ advent_of_code_2019 git:(master) /Users/andrea/.virtualenvs/aoc/bin/python /Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py
Traceback (most recent call last):
File "/Users/andrea/Documents/advent_of_code_2019/aoc/aoc_03.py", line 70, in <module>
with open('aoc_03_input.txt', 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'aoc_03_input.txt'
My guess is that when invoked from VSCode, the script is run from a different path, so it cannot find the file aoc_03_input.txt which is located in the same folder of the script.
How do I tell VSCode to run my script from the /Users/andrea/Documents/advent_of_code_2019/aoc/ folder, so that it will be able to find my input file?
Thanks
Actually, I should have tried more before asking this question, because I just found the solution, but at this point I will write it here in case it can be useful to anyone:
If I change the path in this way:
with open('./aoc_03_input.txt', 'r') as file:
The file is being open correctly when I run the code in VSCode and when I run it from the terminal. Tested under OSX (but it should work under Linux too. Not sure about Windows).
Today I tried to create a new python project unsing Pycharm, with Python3.2. But I figured out that something is wrong.
When I tried to find the path of my python interpreter, I get that one:
Python 3.2 (r32, Apr 18 2018)
>>> import sys
>>> print(sys.executable)
/usr/local/bin/python3.2
So I put this path on the filling section Base interpreter.
Windows python interpreter Pycharm Project
But when pressing button Create project, this error occurs:
Traceback (most recent call last):
File "/home/David/pycharm-community-2018.1.1/helpers/packaging_tool.py", line 159, in main
retcode = do_untar(name)
File "/home/David/pycharm-community-2018.1.1/helpers/packaging_tool.py", line 100, in do_untar
tar = tarfile.open(name)
File "/usr/local/lib/python3.2/tarfile.py", line 1744, in open
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully
Could someone tell me what is wrong? Thanks.
I've got stuck with exactly the same thing and found the answer here:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206601205-Can-t-Install-setuptools-from-within-PyCharm-on-Linux?page=1
You have to compile zlib and recompile python with zlib headers path.
Here's how to compile Python (don't forget the -with-zlib part):
https://stackabuse.com/install-python-on-mac-osx/#installpythonfromsource
Hi I'm new to python and pygame but I am using Atom but I can't solve this problem. When I open my script in IDLE it works but I can't make it work on Atom (specifically terminal-plus) and Terminal. My error message is
Traceback (most recent call last):
File "cargame.py", line 32, in <module>
carImg = pygame.image.load('racecar.png')
pygame.error: Failed loading libpng.dylib: dlopen(libpng.dylib, 2): image not found
so can anyone help?
Perhaps the reason why pygame can't load the image is because it has no context of where the module is being loaded from. Make sure the module (essentially the file where your source code exists), and image file exist in the same environment on disk (the same folder). Otherwise pass an absolute path to the load function and see if the image can be located.
I have created a Python program which works great on windows, but now I have brought it over to my Apple Mac to test it out. The application has a sqlite database and I also have a couple of error logging files which are being kept in when the application is installed or simply initialised from the source code.
On the windows platform, to define the the database path I used the following command:
appDataPath = os.environ["APPDATA"] + "\\FOLDERNAME\\"
But on my mac, I am getting the following stack trace:
Traceback (most recent call last):
File "main.py", line 9, in <module>
from view import tick
File "/Users/myname/Desktop/APPNAME/view/tick.py", line 8, in <module>
from controller import get
File "/Users/myname/Desktop/APPNAME/controller/get.py", line 4, in <module>
appDataPath = os.environ["/Users/myname/Desktop"] + "\\FOLDERNAME\\"
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: '/Users/myname/Desktop'
What can I do to make this work? I tried changing this to my desktop location but still no joy. Where does a mac store the applications data? On Windows as you may very well know, is in the Roaming directory.
Thanks in advance
os.environ is a dictionary containing environment variables. There is no variable called /Users/myname/Desktop. That's why you're getting a KeyError. But there is a variable called HOME.
>>> os.environ['HOME']
'/Users/NAME/'
That should work equally on windows and OSX.
Now, if you want to concatenate paths, you should use os.path.join:
>>> os.path.join(os.environ['HOME'], 'MYPROJECT')
'/Users/NAME/MYPROJECT'
Hi
I'm not familiar with python, I just want to check something so I tried to run a .py code in linux so I wrote :
./waf wifi-olsr-flowmon --plot
which is a .py program after that whatever I want to run just see these error:
/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/wscript: error: Traceback (most recent call last):
File "/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/.waf-1.5.16-e6d03192b5ddfa5ef2c8d65308e48e42/wafadmin/Utils.py", line 197, in load_module
exec(compile(code,file_path,'exec'),module.__dict__)
File "/home/bahar/Desktop/ns/ns-allinone-3.9/ns-allinone-3.9/ns-3.9/wscript", line 32, in <module>
import cflags # override the build profiles from waf
ImportError: No module named cflags
I dont know what does it mean or why it happened, would you please tell me what is the problem .
may be I should add this note that even now that I don't want to run any .py code and just wana run .cc I can't do it and see this error always
Bests
It means that Python was unable to locate a module named cflags, but the code you're running tries to import it. Perhaps you need to set PYTHONPATH, or install the cflags module.
(Also, paragraphs are your friend.)