Unable to run python code from Linux command line - linux

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

Related

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.

Execute Python Script with Command Prompt

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

import module error python3 xubuntu 19.04

When importing PyGame using the interpreter it is successful. Using Geany it is not.
shows the error.
I have tried editing the shebang, renaming the file. making sure the PATH and version were correct, and that there were no missing Geany plugins.
import pygame
pygame.init()
Error in Geany:
Traceback (most recent call last):
File "moduleerror.py", line 3, in <module>
import pygame
ImportError: No module named pygame
I went into Build >> Set Build Commands and under Execute commands changed
python "%f"
to
python3 "%f"

Jupyter Notebook in Anaconda Not Loading

Whenever I try to open Jupyter Notebook from the Anaconda GUI (or conda terminal), I get the following error:
Traceback (most recent call last):
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 10, in
import sqlite3
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\sqlite3\__init__.py", line 23, in
from sqlite3.dbapi2 import *
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\sqlite3\dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: DLL load failed: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
from notebook.notebookapp import main
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\notebookapp.py", line 86, in
from .services.sessions.sessionmanager import SessionManager
File "C:\Users\loops\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 13, in
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I've gone so far as to uninstall Python, uninstall Anaconda, remove all python related path variables, and reinstall Anaconda with Python. This still has not worked. Is there any way to resolve this error? I've looked on many different sites but I haven't found much help.
EDIT: To add more context, it broke randomly one day and I don't have the slightest idea why. Anaconda had worked for a year or so prior. I checked both scripts that are referenced in the error prompt and they both exist in the directory.
I had the same problem.
The issue seems to arise from the missing of sqlite3.dll in the path ".\Anaconda\Dlls".(if using an env, you should put it under the env directory like ".\your env\DLLS") I solved it by simply copying that .dll file from others and put it under the path mentioned above.
You can download the sqlite3.dll from this link: sqlite3.dll

Imports not found when running script outside of Pycharm?

I have a project structured this way...
main.py imports scripts from subfolders like so:
from controllers.available_balances_controller import available_balances_controller
Subfolders:
models
views
controllers
When running main.py in Pycharm it works find.
When I try to run in terminal I get import errors:
Traceback (most recent call last):
File "main.py", line 6, in <module>
from controllers.available_balances_controller import available_balances_controller
ImportError: No module named controllers.available_balances_controller
Am I importing the scripts wrong in main.py?
What is the proper way to do the importing?
Try running your script with the -m flag:
$ python -m main
That means that you are running your main.py as a module inside a python package, not as a simple script. PyCharm makes it easy for you by assuming so when you create a project. When you are in the terminal, you need to specify it yourself. You don't need __init__.py files inside your directories in Python3.
Check out:
https://docs.python.org/3/reference/import.html
Relative imports in Python 3

Resources