I'm having trouble running some codes that import cx_Oracle in command line, though the same codes work in console. Is there anything else I will need to set up in order to get this to work via command line please?
Saved just one line of code "import cx_Oracle" as test.py.
Run this line in ide (Spyder), iPython Notebook => no issues
run this by opening a command line window from the same folder the .py file is saved in, and run python test.py and encounter the below:
import cx_Oracle
ImportError: DLL load failed: %1 is not a valid Win32 application.
Not sure if there is anything additional I will need to set up to run cx_Oracle via command line? Have tried all the suggestions on setting PATH, ORACLE_HOME, re-installing but could not get this to work. versions that i'm using are
Python: 2.7
cx_Oracle: cx_Oracle-5.1.3-11g.win-amd64-py2.7
instant client: 12.1.0.0
Windows: 7 Enterprise
I also found this kind of problem.
Look at "not a valid Win32 application" this sentence, so I decide to change cx_Oracle to cx_Oracle-5.1.3-11g.win-32-py2.7. Luckly, it does work.
Related
I am using a Python 2.7 virtualenv with the MySQLdb package installed.
If I run Python from the command line and execute import MySQLdb, this works without error. If I run it from the PyCharm terminal, however, I get an error:
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory
The same pattern occurs if I execute a file test.py containing the line import MySQLdb. It works when executed from the command line and crashed when executed from PyCharm.
I have googled the error and it seems that uninstalling and reinstalling MySQLdb could fix it. But I would like to understand why the error only occurs in PyCharm.
I have made sure that both the command line and the PyCharm terminal use
the same virtual environment (by checking sys.executable)
the same working directory (by checking os.getcwd())
the same path (by checking sys.path)
I have also checked that PYTHONPATH is undefined.
What other difference could there be?
You have to point pycharm to your virtualenv. Go to settings -> project interpreter and give pycharm the path to your python executable. Once there it should work. Note if you have a hybrid WSL/windows setup you will need one virtualenv for WSL and a separate virtualenv for windows/pycharm.
How do we get ctypes.CDLL("jvm.dll") to not find the dll and not give a "module not found" error?
We have verified the paths and can get them through file "open" commands of the jvm.dll - but the exact same paths when given to ctypes gives a "module not found" error.
We also tried editing the registry keys as per this answer.
We have also tried both running a 32 bit version of Python with a 32 bit version of Java as well as trying 64 bit versions.
We are working in Python 2.7.14 on Windows Server 2016.
Why could this be failing and what else can we try? Is there something preventing the Python script from seeing DLLs?
Here is more background:
The reason we are trying to get ctypes to work is because jpype is failing with the same error- and thus they seem foundationally related to the Python modules not being able to see or access the DLL.
When we run the following commands...
>> import ctypes
>> import os
>> os.chdir(r"C:\Program Files (x86)\Java\jre1.8.0_181\bin\client\")
>> ctypes.CDLL("jvm.dll")
...we get "module not found."
Yet, we can reach the file with open commands. For example, this call works from within Python (note it also works for the x86 path used above) to reach the jvm.dll:
>>> fo = open("C:\\Program Files\\Java\\jre1.8.0_181\\bin\\server\\jvm.dll")
But this call via Jpype fails even though is pathed to the same file:
>>> import jpype
>>> jpype.startJVM("C:\\Program Files\\Java\\jre1.8.0_181\\bin\\server\\jvm.dll")
Jpype gives the following error:
File "C:\Python27\lib\site-packages\jpype_core.py", line 70, in
startJVM
_jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [C:\Program Files\Java\jre1.8.0_181\bin\server\jvm.dll],
error = The specified module could not be found. at
native\common\include\jp_platform_win32.h:58
The reason we are using jpype is we are trying to get Jaydebeapi working to create a JDBC connection to a database.
How do we enable ctypes (and presumably thus jpype) to find and use the jvm.dll?
Our answer to solving this was to move from using the Python 2.7 interpreter to using Jython.
Using Jython, we were able to use the Jadebeapi library and connect to the database over JDBC.
I have been trying enter couple of commands on a command window with python script. I was able to open the .exe file by checking the other questions.
However, now my code:
import os
os.chdir(r'filepath')
os.system("start /B start filepath\application.exe")
opens the application and it asks for an input file name, then it will ask for output file name. Is there a way to do that. This will be used for ArcGIS so it needs to be done in python 2.7.
I checked all related questions but did not find the answer. I would appreciate it very much if you could help.
Finally! It was easier than I thought but I needed lots of research. This code for python 2.7 which may differ for other versions.
import os
import subprocess
os.chdir(r'filepath')
subprocess.check_call([r"filepath\your_.exe_app", 'your_input'])
(Modified to answer the questions in the first comment.)
I am using Flask in PyCharm and getting different results than when I run it from the terminal. In particular, the working directory of the Python program is different under Pycharm. So this code works correctly when running flask from the command line and the print os.getcwd() displays '/Users/Wes/Dropbox/Programming/Python/etpruncnt2'.
However if I run the same code in Pycharm the os.getcwd() displays '/Applications/PyCharm.app/Contents/bin' and the file open fails
with IOError: [Errno 2] No such file or directory: 'data/results.json'.
The root of the project in PyCharm is /Users/Wes/Dropbox/Programming/Python/etpruncnt2. I have also added a screenshot of the project structure in the PyCharm GUI.
I suppose I must have the configuration wrong in PyCharm. I have included a screenshot.
What should I do?
#app.route('/running_count')
def running_count():
print os.getcwd()
with open('data/results.json', 'r') as resultFile:
resultData = json.load(resultFile)
return str(resultData)
You Only Have Shown Script Path
How is project structure ? When you are creating new project you are telling pycharm the project root and may you mixed that part :)
I am going to close this. The immediate problem is that the Working Directory in the config was not filled in.
Most default setups for PyCharm do fill that in, but the setup for flask does not.
I have filed a low-urgency bug report with IntelliJ.
I'm, working on Windows 8 and I receive this error when launching my python program on pycharm:
ImportError: No module named Qwt5
refered to the line: "import PyQt4.Qwt5 as Qwt"
the program always worked till today, and the IDE still suggests me Qwt5 as a module to import when pressing CTRL+SPACE, so it seems is still recognized.
I checked the Qwt5 folder and there is the __init__.py file
I use Python 2.7.9 an is correctly selected as Python Interpreter
I've already tried to remove the packages and reinstall them.
Someone can help me?
i tried this and working.sudo apt-get install python-qwt5-qt4