Run pycharm project outside of pycharm?
Answered
I can run my project with the normal run/debug settings within pycharm, but this is not practical to always have pycharm running. I just want to be able to have my python project running in the console without the weight of pycharm. This isn't exactly obvious on how to do that.
Currently im running off pipenv with some pip modules.
Please sign in to leave a comment.
When using some virtual environment, you can activate that environment and run the needed script from it.
PyCharm does nothing fancy to run your files unless you do something unusual in your run configuration.
PyCharm also shows you the executed command in the Run tool window which you can copy, paste to the system terminal and run.
By run tool window do you mean the menu to edit run configurations?
I'm not sure where the executed command is located.
More detailed instructions would be appreciated, thanks!
Here, when I run the file, I can see the executed command:
Oh I see! Thanks a lot for your help. :)
This is a really good question, but unfortunately, I have not been able to find the answers.
What if my Pycharm project has a lot of dependencies with other projects? And I want to run just the project on another machine?
The problem I've run into is two-fold:
1. Just copying the source to a directory on a remote machine will lead to issues because Python won't find the dependencies. Somehow Pycharm helps the project find it's dependencies. What if I'm running the Python project sans Pycharm? Do I have to all ALL the dependencies' folders to my PYTHONPATH system variable?
2. It's a real pain to have to find all the dependencies and copy them to the new machine. Surely Pycharm can automate this?
Thanks,
Phil
PyCharm can help you add dependencies to PYTHONPATH, there are couple of ways to do that:
- You can add them to interpreter paths.
- You can mark directory as source, thus adding it to PYTHONPATH. For dependencies outside your project, you can also add them as content root to project structure, and then mark as source.
As for running project on remote machine, you must have all dependencies on remote machine as well. PyCharm cannot find and copy all dependencies for you automatically, unfortunately. You can configure additonal path mappings in deployment if you want to copy files from outside project root to the remote host on regular basis.
Thanks,
I did also add content roots to PYTHONPATH
and also added source roots to PYTHONPATH
But still no luck for me getting my main script of the project running independently of Pycharm. Any ideas welcome, thanks, Phil
IDE doesn't have an effect on your environment when running from external terminal. If you use PyCharm's built-in terminal, you can modify your environment from terminal settings:
For everyone need the solution,
I solved it by adding the below lines of code in my main python executable .py file
im running under VENV, python v3.8
"import grpc
import os
import sys
# Get the directory path of the app_root_path's folder
app_root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Get the directory path of the server_path's folder
server_path = os.path.dirname(os.path.abspath(__file__))
# Get the directory path of the application_path's folder
application_path = os.path.join(app_root_path, 'Application')
# Adding the paths to the sys Environment paths
# so that all imports will be known in the python runtime environment - externally to the pycharm IDE runtime!!!
sys.path.append(app_root_path)
sys.path.append(server_path)
sys.path.append(application_path)
# below are Classes defined under the Server_path folder which is the current directory
import Server.ModelService_pb2_grpc as model_service_grpc_pb2
import Server.ModelService_pb2 as model_service_pb2
# below are Classes defined under the application_path
from Application.source.ModelExecutor import ExecuteApplication"
the comment reflects the changes and the environment needed in order to run this .py file externally from pycharm withuot any more information
this describes the folder structure for all imports folder needed
hopes this will help someone in the future