Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pythonrc.py is not loading in interactive mode

I've added a .pythonrc.py script to my home directory with the commands below:

import os
import sys
print 'Welcome'

I've confirmed that it is actually executable by running python .pythonrc.py and by loading the python interpreter and running execfile('.pythonrc.py'). However, when I start interactive mode, it seems that the script is never being loaded. Calls to methods in os or sys return errors that os or sys are not defined. Has anyone seen this before? Any suggestions?

I'm running Python 2.6 on an Ubuntu 10 server.

Thanks!

like image 873
Nate Kennedy Avatar asked Jan 29 '11 13:01

Nate Kennedy


1 Answers

You should set the Environment variable PYTHONSTARTUP to point to the start up script that you created.

In Ubuntu you can edit the ~/.bashrc file and add this line in the end:

export PYTHONSTARTUP=~/.pythonrc.py

Now you should start a new shell and run python.

Hope it helps :)

like image 148
mouad Avatar answered Sep 24 '22 03:09

mouad