Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Import Problem
#1
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.
Reply
#2
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.
Reply
#3
(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
Reply
#4
is there a program named threenames.py in the same directory?
Reply
#5
maybe if you put everything in the same directory ...
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
(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.
Reply
#7
It needs to be in, and current working directory needs to be in the same directory as the calling program.
Reply
#8
(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?
Reply
#9
I figured out my problem! Thank you to everyone who tried to help! :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in import module from other folder akbarza 5 1,445 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  [WORKED AROUND] Problem installing elitech-datareader, 'cannot import build_py_2to3' NeilUK 4 1,735 Jul-09-2023, 10:01 AM
Last Post: NeilUK
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,916 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Import XML file directly into Excel spreadsheet demdej 0 862 Jan-24-2023, 02:48 PM
Last Post: demdej
  How from sklearn.datasets import load_diabetes change to import to CSV file Anldra12 0 1,862 Dec-25-2021, 07:20 PM
Last Post: Anldra12
  How to import file and function in another folder SriRajesh 1 3,176 Dec-18-2021, 08:35 AM
Last Post: Gribouillis
  Import requests/beautifulsoup problem Jokadaro_ 3 2,064 Dec-05-2021, 01:22 PM
Last Post: Jokadaro_
  Python - Import file sequence into Media Pool jensenni 1 2,155 Feb-02-2021, 05:11 PM
Last Post: buran
Smile Import error with local file colt 1 1,954 Nov-08-2020, 07:56 AM
Last Post: Gribouillis
  Problem with Flask Bcrypt import module marcello86 2 5,754 Aug-31-2020, 08:10 PM
Last Post: marcello86

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020