Why can't I import Python modules from my current directory into CASA 5.1?
Posted by Paul Fisher, Last modified by Sarah Wood on 29 September 2017 08:21 PM
Due to changes in the new version of IPython, CASA 5.1 no longer includes the current directory in the PYTHONPATH. In the previous versions of CASA, to import a file named "xxx.py" from the current directory, one would merely type in CASA:|
That no longer works because the current directory is not searched as a possible location for Python files. So, you must now add the current directory to the PYTHONPATH. This may be done by including in your .casa/init.py file a line calling the sys.path.append() function with two single quote characters (not a double quotation mark) as the argument:
Alternatively, after starting CASA, one could simply issue a command to update the path by typing
sys.path = [''] + sys.path
where the characters within the brackets are again two single quotes representing the empty string, which means "current directory" to Python.