I have pyCharm project in which all of my folders have an __init__.py file, and so they are in the Python package.
When I right click on my bootstrap python file and run it, everything runs correctly, but when I execute "python server.py" from the command line I get the error:
/usr/bin/python: No module named agent_module.server_command
How can I run my project from command line?
Related
I'm trying to run a python script in WSL that runs Ubuntu.
In WSL, the following command does not work:
admin:/mnt/c/Users/admin$ /mnt/c/Users/admin/repo/env/Scripts/python.exe /mnt/c/Users/admin/repo/script.py
C:\Users\admin\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file '/mnt/c/Users/admin/repo/script.py': [Errno 2] No such file or directory
However, the following individual commands work:
admin:/mnt/c/Users/admin$ /mnt/c/Users/admin/repo/env/Scripts/python.exe repo/script.py
admin:/mnt/c/Users/admin$ /mnt/c/Users/admin/repo/env/Scripts/python.exe
admin:/mnt/c/Users/admin$ cat /mnt/c/Users/admin/repo/script.py
Why am I seeing this strange behavior? How do I run a python script using absolute path?
When I try to run the main script file of a Python package, from Windows cmd prompt, I get Python errors.
I downloaded a folder from github, that contains a multi-folder Python package, to a folder zzz\ on my Windows 10 computer. The package's top folder is OJWALCH_sleep_classifiers.
To run the package, I must run this module:
zzz\OJWALCH_sleep_classifiers\source\preprocessing\preprocessing_runner.PY
I can't figure out how without error.
I opened a cmd prompt and did cd into zzz\OJWALCH_sleep_classifiers.
Here is what I've tried:
1st attempt...
At cmd line: python -m path and name of module
python -m source\preprocessing\preprocessing_runner
ERROR:
C:\Users\Doug\AppData\Local\Programs\Python\Python37\python.exe: No module named source\preprocessing\preprocessing_runner
2nd attempt...
At cmd line: python <path and name of module>.py
python
python source\preprocessing\preprocessing_runner.PY
ERROR:
Traceback (most recent call last):
File "source\preprocessing\preprocessing_runner.PY", line 3, in <module>
from source.analysis.figures.data_plot_builder import DataPlotBuilder
ModuleNotFoundError: No module named 'source'
3rd attempt... CAN'T FIND MODULE: preprocessing_runner
At cmd line: python <path and name of module>
python source\preprocessing\preprocessing_runner
ERROR:
(null): can't open file 'source\preprocessing\preprocessing_runner': [Errno 2] No such file or directory
At cmd line: python -m path and name of module
This way, because you are giving the name directly to Python, you should use . between folder names, and no file name extension - because you are naming a package and module, not a path and file. So:
python -m source.preprocessing.preprocessing_runner
At cmd line: python .py
This would have worked, except that you tried to start Python first, and then give a command-line command to Python, instead of giving it to the command line.
At cmd line: python
Since this is a single command that starts up Python, we are giving it a path and file. So there should now be a .py extension:
python source\preprocessing\preprocessing_runner.py
We can also use forward slashes at the command prompt - it will break tab-completion, though.
I am trying to run a python programme called helloWorld.py from the command line on MacOS.
I am typing into bash:
Ryans-MacBook-Air:~ ryanunderwood$ python3 helloWorld.py
But I am getting the following:
/Library/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'helloWorld.py': [Errno 2] No such file or directory
There is definitely a file with this name in the directory. Why is this programme not running?
Try ./helloworld.py or python3. /hello World.py
And make sure you have the right permissions
flask question: I have my run.py file in the following dir
/Users/`<username>`/Python_stuff/flask
but when I run it it says
(api_automation)MacBook-Pro:flask `<username>`$ ./run.py
-bash: ./run.py: flask/bin/python: bad interpreter: No such file or directory
I'm confused as to why this is happening when its worked in the past on other virtualenv's
here is what the run.py looks like:
#!flask/bin/python
from app import app
app.run(debug = True)
Your file starts with a shebang telling the shell what program to load to run the script. The shebang line is the first line starting with #!.
In this case, the shebang tells the shell to run flask/bin/python, and that file does not exist in your current location.
The tutorial you got this from expects you to create a virtualenv directory called flask, and the script is set up to run the Python binary installed in that directory.
If you are using a different Python location, edit the shebang line to point to the correct location, or use python run.py to explicitly name the executable on the command line. In that case the shebang line is ignored.
I'm trying to run wlst script form .py file but it can not be done
Content of .py file :
connect('weblogic','weblogic','t3://localhost:8001')
sca_undeployComposite('http://localhost:8001','Hello','1.0','user='weblogic',partition='myPartition')
sca_deletePartition('myPartition')
sca_createPartition('myPartition')
sca_deployComposite('http://localhost:8001','C:\WLST\Test\Application.zip',user='weblogic',configplan='myPlan.xml', partition='myPartition')
exit()
when i run cmd file to execute script, Only connect() method is execute success. any command bellow it can not be execute. And error message appear: Problem invoking WLST - Traceback (innermost last): File "c:\WLS\script\filname.py", line 2, in ?
Name Error: sca_undeployComposite
Please help me to resolve it. Thanks !
The commands after the connect() line which are not regular WLST commands. They requires sca related libraries into CLASSPATH. if you look into your wlst.cmd or .sh file that is actually calling the environment setup file that could be setWLSEnv.sh/.cmd. If you run that from where you are having the this python script. That script will work, it is simple java CLASSPATH funda nothing else!
Probably you might be running wlst.cmd after navigating to the common bin folder like
cd /oracle/fmwhome/Oracle_SOA1/common/bin/.
instead you can run in your script like this
C:\WLS\script\>/oracle/fmwhome/Oracle_SOA1/common/bin/wlst.cmd filename.py
or
C:\WLS\script\>/oracle/fmwhome/Oracle_SOA1/common/bin/setWLSEnv.cmd
C:\WLS\script\>java weblogic.WLST filename.py
You can also refer for more sca related scripting: WLSTByExamples