0

I have my python files all saved in one directory ('F:\code').

When I enter the Python interpreter from the Windows command prompt :

F:\python
>>>

I can import any .py files created when I entered the interpreter. But I can't import any files created after the interpreter already started. I have to exit the interpreter and then open it again to be able to import any new .py modules.

I have tried:

>>> import sys
>>> sys.path.append('F:/code')
>>> sys.path.append('F://code')
>>> sys.path.append('F:\')
>>> sys.path.append('F:\\')

but get the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'module-whatever'

I have tried artificially creating a .pyc file in the pycache folder in the sub of the directory but that doesn't work either.

I'm not sure why I have to exit and re-enter the interpreter because I would like to be able to write .py scripts on the fly eventually and load them in the interpreter to debug.

Jeeves
  • 424
  • 1
  • 7
  • 25
  • 1
    Possibly Windows file permission shenanigans, see if [this solution](https://stackoverflow.com/a/32509496/) works. Really though, this is something that is hard to reproduce, as I cannot reproduce this issue under my Windows VM (or Linux) – metatoaster May 09 '23 at 05:35
  • @metatoaster - Thank you!!!!! This solution you pointed to worked! I can create the .py file, not need to create a .pyc file and use >>>imp then >>>my_file = imp.load_source('module_whatever','F:/code/module_whatever.py') – Jeeves May 09 '23 at 05:43

0 Answers0