I'm trying to load python script from computer to google colab but is show me importError

- 22,221
- 10
- 124
- 129

- 175
- 1
- 8
-
Try `import abc;print(abc.__file__)` to see if its the script you want. – tdelaney Jun 08 '23 at 00:19
3 Answers
Change the file name abc.py
for something else, like testo.py
and it will work.
from google.colab import files
upload = files.upload()
check with !ls
testo.py
Try:
import testo
testo.myfunction()
hello world !
Explanation: abc
is a built-in module and you should not use that name for your modules. Check this question for more info.

- 2,378
- 2
- 18
- 33
the abc module don't have my_function class/attribute/function/etc in the code this was example for reading the abc module go to python_home/Lib/abc.py and for reading the _abc module that written in C go to https://github.com/python/cpython/blob/master/Modules/_abc.c in github
Actually, you import the built-in module abc which means Abstract Base Classes to create abstract classes so don't create the file with the name abc.py
. *You can see all built-in modules in Python Module Index which you cannot use as file names.
So, you should change abc.py
to other name such as greeting.py
then, importing my_function
from greeting.py
works without error as shown below:
# "main.py"
# ↓ Here
from greeting import my_function
my_function() # hello world
In addition, importing def.py
below gets SyntaxError: invalid syntax
error because def
is a reserved word to define functions. *You can see all reserved words in 2.3.1 Keywords and don't use abcdef
's abc
and def
as file names:
import def # Error

- 22,221
- 10
- 124
- 129