Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Path
#1
Hi All,

I'm quite new to python.

I did a default installation of PyCharm on Mac OS and also installed python latest version on Mac.
Whenever I run a .py I need to add that PY name to script path in PyCharm. Can't I just tell PyCharm to run all scripts that I save to /Users/myusername/PycharmProjects folder?

I need to edit configuration and point to the new .py I create every time if I need to run.

Please help.
Reply
#2
Look at Configure a Python interpreter
Then Setting the default interpreter.
For default folder Settings | Appearance & Behaviour | System Settings | Default directory
Restart💤
Reply
#3
(Jul-05-2022, 09:14 PM)snippsat Wrote: Look at Configure a Python interpreter
Then Setting the default interpreter.
For default folder Settings | Appearance & Behaviour | System Settings | Default directory
Restart💤

Thanks for the help.
I tried this but still same issue.
If I set the script path to /venv then I get error. I need to specify the .py file and then only that py file runs. others don't run.

Attaching some screenshots

Attached Files

Thumbnail(s)
       
Reply
#4
Most command shells have tools for doing this sort of thing. A bash shell script
#!/bin/bash

for py_file in $(find /Users/myusername/PycharmProjects folder *.py)
do
    python $py_file
done
I'm sure something similar can be done in the power shell or which ever shell you prefer.
Reply
#5
(Jul-06-2022, 10:12 PM)deanhystad Wrote: Most command shells have tools for doing this sort of thing. A bash shell script
#!/bin/bash

for py_file in $(find /Users/myusername/PycharmProjects folder *.py)
do
    python $py_file
done
I'm sure something similar can be done in the power shell or which ever shell you prefer.

Thanks for the script. Do I need to run this all the time?

ideally which ever .py exits in my projects folder I should be able to run it without changing the path every time.

Im looking for some solution like this. I guess I am doing some mistake in the interpreter or script profile path settings.
Reply
#6
Please ignore my previous post. Do you want to know how to automatically load the correct virtual environment to run the Python script loaded in the editor?
Reply
#7
(Jul-07-2022, 12:35 PM)deanhystad Wrote: Please ignore my previous post. Do you want to know how to automatically load the correct virtual environment to run the Python script loaded in the editor?

Yes please if you can point me to the correct link to load the correct environment then it would be great
Reply
#8
From the beginning, are you using virtual environments and/or a virtual environment manager? Recommend you do so, good form in Python.

Then try Run->Edit Configurations->Working Directory and change that.
I don't use Pycharm or Mac, but the above is what I found with a little searching.
Reply
#9
Hello Everyone,
Looks like I managed to run any .py I want now.
I changed working directory to my directory where the .py files are stored
and now to run any py I right click the tab on the .py and choose run.
This works fine and is enough for me.
Thanks for all your support
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Script File Failure-Path Error? jerryf 13 3,558 Nov-30-2022, 09:58 AM
Last Post: jerryf
  Simple Python script, path not defined dubinaone 3 2,745 Nov-06-2021, 07:36 PM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,244 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,815 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020