Forums

Importing from a symbolic link

Hello:

If I do:

import foo

And foo.py is a symbolic link to another foo.py somewhere else on PythonAnywhere it doesn't work.

If I copy foo.py it works (obviously). But I don't want multiple copies of the same code lying around, and so symbolic links seemed the obvious solution.

Does anyone know why this doesn't work, and can anyone suggest how I solve the problem

Thanks Robert

hmm. Do you know what the error stack trace is when it doesn't work?

A couple things to double check: Do you know if the sym link was created correctly? eg: did you use an absolute path for the target, and if you cat the symlink'd file, does it show the correct code?) Or potentially the file tries to do something that makes use of the its own path/working directory and the new symlink'd file breaks that?

Thanks Conrad :-)

You solved my problem; my symlink did not have an absolute path for the target, just a relative one. And I learnt something new.