6

I am trying to do what the user from this question is doing. I have it working for the separate IPython console but not the one integrated into PyCharm.

To sum up, I want IPython to import some modules when I start it. I have gone to the C:\Users\Name\.ipython\profile_default\startup directory and I have made a startup.py file which contains

from numpy import *
print 'NumPy imported succesfully!'

After setting PYTHONSTARTUP to point to the file, the IPython console outside of PyCharm works as intended, but the one in PyCharm does not.

Community
  • 1
  • 1
turnip
  • 2,246
  • 5
  • 30
  • 58
  • http://stackoverflow.com/questions/30405804/how-do-i-permanently-set-the-current-directory-to-the-desktop-in-python/30405876#30405876 – Padraic Cunningham Aug 12 '15 at 17:32
  • Thanks @PadraicCunningham. I followed the steps and it works but only for the separate IPython console - I was trying to get the one in PyCharm to do the same thing. I have edited my question accordingly. – turnip Aug 13 '15 at 08:50
  • The problem is the environment variable is only being recognised when you run the process from a `cmd/shell`, it is the same on linux where you would set an environment variable in `.bashrc` or the equivalent file using other shells, unless you start the application from bash then the environment variable is not set, on ubuntu I have it set in `/etc/environment` with `export PYTHONPATH=/home/padraic/mymods/` so it is set globally. You would need to either run pycharm from the cmd or use the equivalent to setting a global environment variable. – Padraic Cunningham Aug 14 '15 at 17:55
  • I am not overly familiar with windows so not sure what the different methods are to set the environment variable, I always presumed they were global when you set them as in the linked question – Padraic Cunningham Aug 14 '15 at 17:57

1 Answers1

6

You can go to File -> Settings -> Build, Execution, Deployment -> Console -> Python Console. There you have a field named "Starting script" which is executed when you launch the console.

I had to restart PyCharm for the changes to actually take place, but it worked.

Note : I use PyCharm 4.5.3 Community Edition.

Kolaru
  • 176
  • 2
  • For those of you searching for problems related to the extension "autoreload" this also works for that. No need to add a config file, in the Starting Script box you can place two lines `%load_ext autoreload` and `%autoreload 2` and it will run each time you launch the console. – Jared Marks Jun 07 '18 at 16:58