0

I'm running Window 10 64-bit. I have a Python project:

A:\code\projectFolder\project.py

For project.py, I want to import the following file:

A:\code\importThisFolder\importThisFile.py

On project.py, I've tried using without success:

import sys
sys.path.insert(0,'A:\code\importThisFolder')
import importThisFile

Can someone please help me with my import issues?

Robin Alvarenga
  • 321
  • 2
  • 14
  • 1
    Possible duplicate of [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – the.salman.a Mar 22 '18 at 05:57
  • I've read that question before I posted my own question. I've used the sys.path.insert() method with no success. – Robin Alvarenga Mar 22 '18 at 06:03
  • 3
    Your backslaches (`'\'`) could be the issue. Use `r'A:\code\importThisFolder'` instead. – busybear Mar 22 '18 at 06:03

3 Answers3

0

Okay, looks like I had a mispelling and accidently used the wrong backslash. The appropriate backslash is '\'. I accidently used '/'. Thanks @busybear !

Robin Alvarenga
  • 321
  • 2
  • 14
0

the simple solution is to put both file in same directory and then just write import thisfile or from thisfile import file.

if you put both script in same folder then it won't create any issue.

SarwarKhan
  • 133
  • 1
  • 2
  • 10
-1

Don't. Simply move both .py files to the same directory and simply use:

import my_file

Alternatively, you can move your .py file to your site-packages folder.

James
  • 274
  • 4
  • 12
  • 1
    Not only this is not always possible, but it is also undesirable if the module is a part of another project. – DYZ Mar 22 '18 at 06:10