Execute Python Script with Command Prompt - python-3.x

I am pretty new in Python. I have created my first program script in pyhton, using spyder. I am getting below error when executing the python script through Command Prompt.
Error - C:\Users\rkuma388\Documents\Project\Python>ETL_ProvJenny_ReportScreen_CoachListLoad.py
Traceback (most recent call last):
File "C:\Users\rkuma388\Documents\Project\Python\ETL_ProvJenny_ReportScreen_CoachListLoad.py", line 10, in
import pandas as pd
File "C:\Users\XXXXX\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_init_.py", line 19, in
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
but when running in spyder, it is running fine and giving output.
Do I need to install any additional thing to make it execute in CMD ? Please suggest.
Thanks in advance.

Following are the options you can try:
Even though it is not a real solution, you can uninstall and reinstall numpy with pip.
Check whether you PATH is configured correctly to point to Python folder

Related

H5py Driver Issue on Qiskit Nature Drivers

While using the IBM Quantum experience, whenever I want to install any driver an error with the h5py appears.
Specifically, the error is
"Using default_file_mode other than 'r' is no longer supported. Pass
the mode to h5py.File() instead."
Does anyone have any solutions to it (not sure which version to revert back to). Thanks!!
You will need to add more details about your question. I could not replicate your error based on the information you provided. This is what I did:
First, I installed Qiskit Nature with this command pip install qiskit[nature].
Next, I entered the following Python commands:
>>> from qiskit_nature.drivers.second_quantization import HDF5Driver
>>> h5f = HDF5Driver()
>>> h5f
<qiskit_nature.drivers.second_quantization.hdf5d.hdf5driver.HDF5Driver object at 0x7fa28320a820>
>>> h5f.run()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py", line 63, in run
raise LookupError(f"HDF5 file not found: {hdf5_file}")
LookupError: HDF5 file not found: molecule.hdf5
There is no error when I imported the HDF5Driver module from the qiskit_nature package. An error occurs when I enter h5f.run(). This is expected, because I don't have a file named molecule.hdf5 (the default filename). If you have a different filename, modify commands above to use h5f = HDF5Driver("your_filename").
Tests run with Python 3.8.12 and qiskit_nature 0.3.0 running on Ubuntu Linux 5.11.0-1023-gcp.

Cannont run PyGlossary on Windows10

Absolute noob here, so I apologize in advance for stupid questions.
I'm running Windows 10, I've got Python 3.7.3 and I have...
Successfully installed pyglossary-3.2.1
But I cannot run PyGlossary from the command line or the tkinter GUI. If I run any of the following lines
python3 pyglossary.pyw --help
python3 pyglossary.pyw --ui=tk
python3 pyglossary.pyw --version
Nothing happens and I don't get any sort of error message. I've also tried...
python pyglossary.pyw --help
and I get...
Traceback (most recent call last):
File "pyglossary.pyw", line 30, in
from pyglossary import core # essential
File "C:\mypath\pyglossary\pyglossary.pyw", line 30, in
from pyglossary import core # essential
ImportError: cannot import name 'core' from 'pyglossary' (C:\mypath\pyglossary\pyglossary.pyw)
I've checked Windows Path variables, but I think everything's ok there, and I'm able to run other python stuff. Thanks in advance.

Unable to run python code from Linux command line

I have gone through the explanations given in this forum and have tried them in my program. However, none of the suggestions worked. That's why I am opening this thread.
Below is the tree for my project. There are 2 packages: com and main.
When I try to run the code for ProcessRiskModelbyRecordID.py from command line, I am getting below error message:
$ python3 /AppDev/XXXX/py/riskScore/main/ProcessRiskModelbyRecordID.py
Traceback (most recent call last):
File "/AppDev/XXXX/py/riskScore/main/ProcessRiskModelbyRecordID.py", line 6, in
from main.ConnectAPI import *
ModuleNotFoundError: No module named 'main'
When I run the same code from PyDev, I am able to execute it.
Below is the import code from ProcessRiskModelbyRecordID.py:
from main.ConnectAPI import *
from com import DBOperations as DBO,SourceProfile,TargetProfile
Can you please help so that I can run this code from command line?
PyDev is probably setting PYTHONPATH for you. On the command line you would need to set it yourself:
cd riskScore
export PYTHONPATH=`pwd`
python3 main/ProcessRiskModelbyRecordID.py

How to fix Python script started in CMD get's DLL Error, but runs in Pycharm and Anaconda Comand Promt

I want to run a python script in cmd via a batch file. The script fails with dll loading error for numpy imports. The same python script works in pycharm (2019 Anaconda Version) and in the anaconda command prompt without errors.
For all I use the same anaconda enviorment.
For Error Reproduction
Install Anaconda, don't set any path variables
Create an enviorment stored not in the default folder
conda create --prefix
conda activate
conda install numpy flask
6.Code for testing. test-numpy.py
import numpy as np
print(np.abs([1,2-4,6]))
create batch script
run batch script
Running in cmd a python script that has only system imports or no imports works fine.
Setting the pythonpath Variable in Windows is no option.
What I did so far:
Checking if there is an PATH error:
I printed the sys.path, both via Pycharm and the same python script run via CMD gave the same results: it points to my anaconda enviorment with the folders:
...\ (the enviorment itself)
...\python37.zip
...\DLLs
...\lib
...\lib\site-packages
Edit
Tested in Visual Studio Code, gives same Error as running via cmd
Found out Visual Studio Coda until now, can't handle conda enviorments, that where installed with -p or -prefix and are not stored in the default path
Uninstalled and reinstalled numpy
Tested to import another module: Flask also fails with DDL load error but works fine while run in Pycharm.
Tested on another PC with differnt anaconda version.
Another person could reproduce the same error I get.
My guess is my code fails in cmd, becaust anacona enviorments needs somehow to be activated before hand and doesn't work as a stand alone.
The Error Messeag I get running my script in CMD (... points to my anaconda enviormant path):
...\lib\site-packages\numpy\core__init__.py", line 40, in
from . import multiarray ...\lib\site-packages\numpy\core\multiarray.py", line 12, in
from . import overrides ...\lib\site-packages\numpy\core\overrides.py", line 6, in
from numpy.core._multiarray_umath import ( ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): "TestNumpy.py", line 14, in
import numpy as np ...\lib\site-packages\numpy__init__.py", line 142, in
from . import core ...\lib\site-packages\n umpy\core__init__.py", line 71, in
raise ImportError(msg) ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Mostlikely
you are trying to import a failed build of numpy. Here is how to
proceed:
- If you're working with a numpy git repository, try git clean -xdf (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed: your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: Das angegebene Modul wurde nicht
gefunden.
I found not other solution it seems like it is needed to really activate the conda enviorment before calling the script via conda:
call <file_path>/Anaconda/Scripts/activate.bat <file_path/Anaconda_enviorment> && python <file_path/pythonscript.py>

python module not found error

This question has been asked a few times, but the remedy appears to complicated enough that I'm still searching for a user specific solution.
I recently installed Quandl module using pip command. Even after successful installation my python idle is still showing
Traceback (most recent call last):
File "F:\Python36\Machine Learning\01.py", line 3, in <module>
import Quandl
ModuleNotFoundError: No module named 'Quandl'
I have used import command in my code.
I am using python 3.6.1 version.
I am working on a windows 10 Desktop.
I have also tried re-installation of module.
You can better navigate to your python scripts folder and open a command window there and try pip3 install quandl .Hope this helps.

Resources