Python Forum

Full Version: File Import Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I'm new to Python and I've been having a problem with importing a file. It says that there isn't a module named threenames (that is what my file is called)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named threenames

Up there is the exact error that I have been getting. I am following Learning Python by Mark Lutz. It is the fifth edition. I am using Pyton 2.7, and the file isn't showing up in the directory either.
you need to provide more information.
how are you importing, is the file in the same directory as the program importing it?
if not, have you set up an __init__.py which shows project structure?
is the spelling correct (including case if on Linux)

It would be most helpful if we could see your code.
(Aug-04-2018, 02:12 AM)Larz60+ Wrote: [ -> ]you need to provide more information. how are you importing, is the file in the same directory as the program importing it? if not, have you set up an __init__.py which shows project structure? is the spelling correct (including case if on Linux) It would be most helpful if we could see your code.
The file isn't in the same directory as the program importing it, but I have other files in the same directory as threenames which do work. The spelling is correct I have done it multiple times and I have also had other people try which also didn't work.
Down below is what I have been typing. I have done the same things for other files and those have all been successful.
>>> import threenames
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named threenames
is there a program named threenames.py in the same directory?
maybe if you put everything in the same directory ...
(Aug-04-2018, 04:38 AM)Larz60+ Wrote: [ -> ]is there a program named threenames.py in the same directory?
It's in the same directory as other python files that have worked and still work. I assume the problem is that it won't show up when I put in dir even when I'm in the directory that threenames.py is in.
It needs to be in, and current working directory needs to be in the same directory as the calling program.
(Aug-04-2018, 11:33 AM)Larz60+ Wrote: [ -> ]It needs to be in, and current working directory needs to be in the same directory as the calling program.
Why do other files in the same directory as threenames work then?
I figured out my problem! Thank you to everyone who tried to help! :)