Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically run code on Pycharm environment start

I have just started using PyCharm because I want to get more into Python (have more experience with other languages), and have run into a conundrum that there has to be a solution for. Some custom function I created relies on a module being imported in a particularly verbose way, so I don't want to have to copy-paste the same two lines every time I want to code, as opposed to simply typing import numpy as np.

So is there a way to automatically run some code on my environment's start? Particularly to import some modules? I looked around PyCharm's settings, and have found nothing.

like image 547
Coolio2654 Avatar asked Dec 04 '25 14:12

Coolio2654


1 Answers

Do File | Settings | Tools | Startup Tasks (or Ctrl-Alt-S).

Then: Build, Execution, Deployment > Console > Python Console

This gives you a dialogue with an edit box Starting script. Put your import code there. That will run every time you open a new console.

like image 118
BoarGules Avatar answered Dec 07 '25 18:12

BoarGules