Python error "ImportError: No module named"
Asked Answered
E

38

629

Python is installed in a local directory.

My directory tree looks like this:

(local directory)/site-packages/toolkit/interface.py

My code is in here:

(local directory)/site-packages/toolkit/examples/mountain.py

To run the example, I write python mountain.py, and in the code I have:

from toolkit.interface import interface

And I get the error:

Traceback (most recent call last):
  File "mountain.py", line 28, in ?
    from toolkit.interface import interface
ImportError: No module named toolkit.interface

I have already checked sys.path and there I have the directory /site-packages. Also, I have the file __init__.py.bin in the toolkit folder to indicate to Python that this is a package. I also have a __init__.py.bin in the examples directory.

I do not know why Python cannot find the file when it is in sys.path. Any ideas? Can it be a permissions problem? Do I need some execution permission?

Emmert answered 3/12, 2008 at 21:26 Comment(8)
Check that you have read permission to that file from python. See: https://mcmap.net/q/65229/-how-to-make-my-python-module-available-system-wide-on-linuxAnge
Please be sure to mark your directory as "Resources Root" to let PyCharm know this is a package.Munn
The problem in my case was that there was the permission to newly installed modules were not 755. That was because umask on the machine was 0027 due to which the others did not have read permission causing module to not be read. Adding read permission fixed my problem. It's worth checking the permission of the target directory post-installation.Curio
Try to blow url : #47888114Lording
maybe local directory name is interface (have been a conflict).Theoretician
check things like: is python2 being used instead of 3? Do you files have the proper line ending configured? Are packages properly declared?Croaker
The issue described here is extremely out of date, and the problem in OP's case could not actually be diagnosed from the information that was actually provided in the question. __init__.py hasn't been necessary since Python 3.3 for relative imports, and I can't think of a reason it would ever have been required for absolute imports. Absolutely mind-boggling that this nonsense has millions of views.Leporide
(The given information also doesn't illustrate the actual directory tree nor sys.path accurately enough to be sure of understanding the problem. In particular, I can't fathom what the "local directory" might be, but that sounds unlikely to be a place that makes sense to contain the site-packages sub-directory.)Leporide
F
326

Based on your comments to orip's post, I guess this is what happened:

  1. You edited __init__.py on windows.
  2. The windows editor added something non-printing, perhaps a carriage-return (end-of-line in Windows is CR/LF; in unix it is LF only), or perhaps a CTRL-Z (windows end-of-file).
  3. You used WinSCP to copy the file to your unix box.
  4. WinSCP thought: "This has something that's not basic text; I'll put a .bin extension to indicate binary data."
  5. The missing __init__.py (now called __init__.py.bin) means python doesn't understand toolkit as a package.
  6. You create __init__.py in the appropriate directory and everything works... ?
Froggy answered 4/12, 2008 at 0:17 Comment(7)
Also, python -c 'import sys; print sys.path' helps -- sometimes the user has placed the files in a path not scanned.Hochheimer
I'm using the same thing except WinSCP didn't append .bin.Crissy
if I have a empty "__init__.py" will the same thing happen?Pinchbeck
For me the issue was I was using python driver.py when I should have been using python3 driver.py since I installed with pip3.Supposing
As @EricWiener pointed out, using python 2 may cause this issue aswell. He may be using #!/usr/bin/env python to detect the python environment, and have python2 instead of python3 mapped, which causes that error in some packagesCroaker
to add @Hochheimer comment, from the path, in my case, there is precedent path containing the folder that masks the actual folder I intend to use.Whopper
__init__.py is not needed since 3.3 (although it has some other effects and is often desirable). See peps.python.org/pep-0420.Leporide
N
106

I ran into something very similar when I did this exercise in LPTHW; I could never get Python to recognise that I had files in the directory I was calling from. But I was able to get it to work in the end. What I did, and what I recommend, is to try this:

(NOTE: From your initial post, I am assuming you are using an *NIX-based machine and are running things from the command line, so this advice is tailored to that. Since I run Ubuntu, this is what I did)

  1. Change directory (cd) to the directory above the directory where your files are. In this case, you're trying to run the mountain.py file, and trying to call the toolkit.interface.py module, which are in separate directories. In this case, you would go to the directory that contains paths to both those files (or in other words, the closest directory that the paths of both those files share). Which in this case is the toolkit directory.

  2. When you are in the toolkit directory, enter this line of code on your command line:

    export PYTHONPATH=.

    This sets your PYTHONPATH to ".", which basically means that your PYTHONPATH will now look for any called files within the directory you are currently in, (and more to the point, in the sub-directory branches of the directory you are in. So it doesn't just look in your current directory, but in all the directories that are in your current directory).

  3. After you've set your PYTHONPATH in the step above, run your module from your current directory (the toolkit directory). Python should now find and load the modules you specified.

Nairn answered 22/4, 2014 at 3:52 Comment(4)
Or on Windows set PYTHONPATH=..Fecula
Be careful if you have third party or custom library references in an already existing PYTHONPATH environment variable. If you do the instead run: set PYTHONPATH=%PYTHONPATH%;.; to append . to the PYTHONPATH and then echo %PYTHONPATH% which should display path\to\custom\library;.;. Then run your application from the application directory with python applicationlaunchfile.py.Masterful
You saved me. Thanks! This also works for Python 3.10 in 2022.Throw
Reason why . is not in PYTHONPATH by default: #24436197Higginbotham
R
97

Does

(local directory)/site-packages/toolkit

have a __init__.py?

To make import walk through your directories every directory must have a __init__.py file.

Reagan answered 3/12, 2008 at 21:50 Comment(3)
Good point! Remark: Since Python 3.3, any directory on sys.path with a name that matches the package name will be recognised.Guanine
isn't this only necessary for relative path references? why must every directory have it ?Wakefield
__init__.py is not needed since 3.3 (although it has some other effects and is often desirable). See peps.python.org/pep-0420.Leporide
M
47

On *nix, also make sure that PYTHONPATH is configured correctly, especially that it has this format:

 .:/usr/local/lib/python

(Mind the .: at the beginning, so that it can search on the current directory, too.)

It may also be in other locations, depending on the version:

 .:/usr/lib/python
 .:/usr/lib/python2.6
 .:/usr/lib/python2.7 and etc.
Metropolitan answered 4/3, 2011 at 21:14 Comment(6)
It may also be .:/usr/lib/python, .:/usr/lib/python2.6, .:/usr/lib/python2.7 and etc. depending on the versionThumbnail
For me, the module is in in /usr/local/lib/python3.4/dist-packages but when I type python3 in the terminal (ubuntu), and try to import it, it doesn't allow me, saying that it doesn't exist. "ImportError: no module x exists"Robles
Adding #!/usr/bin/python at the end of a file should work too, right?Plumage
@Plumage I don't think that will work. Plus usually this shebang is added at the top of a file.Metropolitan
-1 Having Python installation directory listed in PYTHONPATH is plainly wrong and shows lack of understanding of what this variable is meant for.Maceio
On MacOSX fixed it by adding PYTHONPATH=/usr/local/lib/python2.7/site-packages to startup scripts.Mooneyham
S
46

You are reading this answer says that your __init__.py is in the right place, you have installed all the dependencies and you are still getting the ImportError.

I was facing a similar issue except that my program would run fine when ran using PyCharm but the above error when I would run it from the terminal. After digging further, I found out that PYTHONPATH didn't have the entry for the project directory. So, I set PYTHONPATH per Import statement works on PyCharm but not from terminal:

export PYTHONPATH=$PYTHONPATH:`pwd`  (OR your project root directory)

There's another way to do this using sys.path as:

import sys
sys.path.insert(0,'<project directory>') OR
sys.path.append('<project directory>')

You can use insert/append based on the order in which you want your project to be searched.

Shanta answered 8/2, 2019 at 16:57 Comment(2)
This is what I did as a workaround. But I still don't understand why this should be necessary. I have, in my Pipfile, a relative path module that cannot be detected (e.g. I get the ImportError) without said workaround.Undertone
This is great. A general way to apply it if you're sure you're in the right path: sys.path.append(os.getcwd())Munition
R
34

Using PyCharm (part of the JetBrains suite) you need to define your script directory as Source:
Right Click > Mark Directory as > Sources Root

Run answered 4/1, 2017 at 17:53 Comment(1)
thank you, this is definitely needed inheriting legacy projects with all modules in a flat hierarchy outside of a /src directoryGrangerize
E
26

I solved my own problem, and I will write a summary of the things that were wrong and the solution:

The file needs to be called exactly __init__.py. If the extension is different such as in my case .py.bin then Python cannot move through the directories and then it cannot find the modules. To edit the files you need to use a Linux editor, such as vi or nano. If you use a Windows editor this will write some hidden characters.

Another problem that was affecting it was that I had another Python version installed by the root, so if someone is working with a local installation of python, be sure that the Python installation that is running the programs is the local Python. To check this, just do which python, and see if the executable is the one that is in your local directory. If not, change the path, but be sure that the local Python directory is before than the other Python.

Emmert answered 4/12, 2008 at 1:11 Comment(3)
A problem I got was that a module was (re)installed by pip with only the root user to access it, so the user that ran the program didn't see it.Elery
@JānisElmeris can you elaborate more on the above comment, I think I am also facing a similar error. I have my __init__.py files placed in relevant directory but I manually installed a package using setup.py. How did installing a new package would interfere imports.Subteen
@darth_coder, sorry, that was six years ago and I don't remember the case. Also, I'm dealing with Python very little, not at all lately. From what I wrote, I can just think that I installed a package as root, which changed the permissions so that other users didn't have the access they had before.Elery
Z
26

For me, it was something really stupid. I installed the library using pip3 install but was running my program as python program.py as opposed to python3 program.py.

Zingaro answered 22/8, 2019 at 16:2 Comment(1)
Thank you! Think this is a common mistake if you're running on a system that has Python2 installed by default (OS X)Doglike
V
21

an easy solution is to install the module using python -m pip install <library-name> instead of pip install <library-name> you may use sudo in case of admin restrictions

Vauban answered 18/9, 2017 at 15:30 Comment(3)
What does python -m achieve in front of pip install?Sulfide
@Sulfide - when you use the -m command-line flag, Python will import a module or package for you and then run it as a script. When you don't use the -m flag, the file you named is run as just a script.Maori
Not sure what this answer is trying to say wrt python -m pip... working, but pip... did not: they are effectively the same thing, assuming they're actually in the same python directory. Possibly, the observed situation was that the stand-alone pip program wasn't available in some older python release (but it is now in latest 2.7 & 3.x). In that case, the python was in a local virtualenv and pip wasn't, so python -m pip install would install in the local virtualenv, whereas pip would try to install in the system python (and fail w/o sudo). In any case, it doesn't make sense.Distributor
L
19

To mark a directory as a package you need a file named __init__.py.

Latinize answered 3/12, 2008 at 21:31 Comment(8)
I already have a file called init.py.bin, If I change the name to init.py, then I get this error: /__init__.py", line 1 "utilities", "demo"] ^ SyntaxError: invalid syntaxEmmert
What's in init.py? Post that as part of your question, please.Ramonaramonda
There is nothing, it is empty, It was with the package that I download, do I need to write something in the file?.Emmert
@S.Lott: you don't need to put anything in your init.py right?Reagan
@Eduardo. Your init.py gets an error. And you say it's empty. That's difficult to reconcile. And it can't be called init.py.bin -- Python would ignore this file. Typically, it can have nothing in it.Ramonaramonda
You were right Lott I edited the file with a windows editor and it wrote some hide characters, now I have create new files with vi.Emmert
@Eduardo: You may want to get Programmer's Notepad or Komodo Edit or something that edits pure text with no hidden special characters. They may be easier to use than vi.Ramonaramonda
Thanks for the advice I usually use nano for edition, the reason why I used a windows editor is because I am working in a cluster, and I use WinSCP to move files and sometimes I use that editor for change files.Emmert
A
8

To all those who still have this issue. I believe Pycharm gets confused with imports. For me, when i write 'from namespace import something', the previous line gets underlined in red, signaling that there is an error, but works. However ''from .namespace import something' doesn't get underlined, but also doesn't work.

Try

try:
    from namespace import something 
except NameError:
    from .namespace import something
Airline answered 11/5, 2019 at 19:34 Comment(2)
The first is python 2 syntax, the second is python 3.Tackett
@TanyaBranagan no, that is simply incorrect. from namespace import something is an absolute import, and from .namespace import something is a relative import. Both can work in either Python 2 or Python 3; each requires separate setup. In Python 2.4, the absolute import syntax used to try relative imports first, and the relative import syntax hadn't been implemented yet. But in 2019 it was rare for anyone to be stuck even on 2.6; Python 2.7 was synonymous with "Python 2" for years.Leporide
W
7

Yup. You need the directory to contain the __init__.py file, which is the file that initializes the package. Here, have a look at this.

The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later.

Winded answered 7/1, 2009 at 14:22 Comment(0)
C
7

If you have tried all methods provided above but failed, maybe your module has the same name as a built-in module. Or, a module with the same name existing in a folder that has a high priority in sys.path than your module's.

To debug, say your from foo.bar import baz complaints ImportError: No module named bar. Changing to import foo; print foo, which will show the path of foo. Is it what you expect?

If not, Either rename foo or use absolute imports.

Candicecandid answered 2/5, 2017 at 6:41 Comment(1)
For me, this yields ImportError: No module named foo.Brezhnev
T
6

My two cents:

enter image description here

Spit:

Traceback (most recent call last):
      File "bash\bash.py", line 454, in main
        import bosh
      File "Wrye Bash Launcher.pyw", line 63, in load_module
        mod = imp.load_source(fullname,filename+ext,fp)
      File "bash\bosh.py", line 69, in <module>
        from game.oblivion.RecordGroups import MobWorlds, MobDials, MobICells, \
    ImportError: No module named RecordGroups

This confused the hell out of me - went through posts and posts suggesting ugly syspath hacks (as you see my __init__.py were all there). Well turns out that game/oblivion.py and game/oblivion was confusing python which spit out the rather unhelpful "No module named RecordGroups". I'd be interested in a workaround and/or links documenting this (same name) behavior -> EDIT (2017.01.24) - have a look at What If I Have a Module and a Package With The Same Name? Interestingly normally packages take precedence but apparently our launcher violates this.

EDIT (2015.01.17): I did not mention we use a custom launcher dissected here.

Toothpick answered 6/9, 2014 at 11:17 Comment(2)
more like the path is off. game.oblivion.RecordGroups !== game/oblivion/patchers/RecordGroups.py May want to fix that with appending your python code to use: game.oblivion.patchers.RecordGroupsDelisadelisle
@DwightSpencer: I am sure I imported the "RecordGroups" in game.oblivion.__init__.py but may have to check thisToothpick
L
6

For me, running the file as a module helped.

Instead of

python myapp/app.py

using

python -m myapp.app

It's not exactly the same but it might be a better approach in some cases.

Logan answered 28/4, 2022 at 13:59 Comment(2)
I don't know what myapp\app vs myapp/app vs myapp/app.py vs myapp\app.py vs myapp.app means, but this fixed it.Slack
same for me, I don't know what the differences are, perhaps I should figure it out but this fixed it for me tooVendible
H
5
  1. You must have the file __ init__.py in the same directory where it's the file that you are importing.
  2. You can not try to import a file that has the same name and be a file from 2 folders configured on the PYTHONPATH.

eg: /etc/environment

PYTHONPATH=$PYTHONPATH:/opt/folder1:/opt/folder2

/opt/folder1/foo

/opt/folder2/foo

And, if you are trying to import foo file, python will not know which one you want.

from foo import ... >>> importerror: no module named foo

Hestia answered 9/1, 2014 at 19:45 Comment(0)
D
4

In my case, the problem was I was linking to debug python & boost::Python, which requires that the extension be FooLib_d.pyd, not just FooLib.pyd; renaming the file or updating CMakeLists.txt properties fixed the error.

Doradorado answered 4/9, 2013 at 2:52 Comment(0)
K
4

Fixed my issue by writing print (sys.path) and found out that python was using out of date packages despite a clean install. Deleting these made python automatically use the correct packages.

Kansas answered 21/7, 2016 at 18:51 Comment(0)
M
4

In my case, because I'm using PyCharm and PyCharm create a 'venv' for every project in project folder, but it is only a mini env of python. Although you have installed the libraries you need in Python, but in your custom project 'venv', it is not available. This is the real reason of 'ImportError: No module named xxxxxx' occurred in PyCharm. To resolve this issue, you must add libraries to your project custom env by these steps:

  • In PyCharm, from menu 'File'->Settings
  • In Settings dialog, Project: XXXProject->Project Interpreter
  • Click "Add" button, it will show you 'Available Packages' dialog
  • Search your library, click 'Install Package'
  • Then, all you needed package will be installed in you project custom 'venv' folder.

Settings dialog

Enjoy.

Magnetomotive answered 18/2, 2019 at 3:35 Comment(0)
D
3

Linux: Imported modules are located in /usr/local/lib/python2.7/dist-packages

If you're using a module compiled in C, don't forget to chmod the .so file after sudo setup.py install.

sudo chmod 755 /usr/local/lib/python2.7/dist-packages/*.so
Dusk answered 30/5, 2014 at 22:50 Comment(0)
G
3

My problem was that I added the directory with the __init__.py file to PYTHONPATH, when actually I needed to add its parent directory.

Greatest answered 27/3, 2018 at 12:41 Comment(0)
H
2

If you are using a setup script/utility (e.g. setuptools) to deploy your package, don't forget to add the respective files/modules to the installer.


When supported, use find_packages() or similar to automatically add new packages to the setup script. This will absolutely save you from a headache, especially if you put your project aside for some time and then add something later on.

import setuptools

setuptools.setup(
    name="example-pkg",
    version="0.0.1",
    author="Example Author",
    author_email="[email protected]",
    description="A small example package",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.6',
)

(Example taken from setuptools documentation)

Hatchel answered 17/10, 2020 at 11:36 Comment(0)
H
1

I had the same problem (Python 2.7 Linux), I have found the solution and i would like to share it. In my case i had the structure below:

Booklet
-> __init__.py
-> Booklet.py
-> Question.py
default
-> __init_.py
-> main.py

In 'main.py' I had tried unsuccessfully all the combinations bellow:

from Booklet import Question
from Question import Question
from Booklet.Question import Question
from Booklet.Question import *
import Booklet.Question
# and many othet various combinations ...

The solution was much more simple than I thought. I renamed the folder "Booklet" into "booklet" and that's it. Now Python can import the class Question normally by using in 'main.py' the code:

from booklet.Booklet import Booklet
from booklet.Question import Question
from booklet.Question import AnotherClass

From this I can conclude that Package-Names (folders) like 'booklet' must start from lower-case, else Python confuses it with Class names and Filenames.

Apparently, this was not your problem, but John Fouhy's answer is very good and this thread has almost anything that can cause this issue. So, this is one more thing and I hope that maybe this could help others.

Hastie answered 27/5, 2018 at 23:49 Comment(0)
S
1

In linux server try dos2unix script_name

(remove all (if there is any) pyc files with command find . -name '*.pyc' -delete)

and re run in the case if you worked on script on windows

Scales answered 17/1, 2020 at 15:7 Comment(0)
E
1

In my case, I was using sys.path.insert() to import a local module and was getting module not found from a different library. I had to put sys.path.insert() below the imports that reported module not found. I guess the best practice is to put sys.path.insert() at the bottom of your imports.

Eisenach answered 10/3, 2020 at 9:55 Comment(0)
S
1

I've found that changing the name (via GUI) of aliased folders (Mac) can cause issues with loading modules. If the original folder name is changed, remake the symbolic link. I'm unsure how prevalent this behavior may be, but it was frustrating to debug.

Sumpter answered 17/2, 2021 at 18:47 Comment(0)
G
1

If you're on a tight deadline and all else fails:

import sys
import os
wd = '/path/to/current/script/'
sys.path.append(wd)
os.chdir(wd)
print(os.getcwd())
print(sys.path)
Guanine answered 15/6, 2022 at 5:55 Comment(0)
C
0

After just suffering the same issue I found my resolution was to delete all pyc files from my project, it seems like these cached files were somehow causing this error.

Easiest way I found to do this was to navigate to my project folder in Windows explorer and searching for *.pyc, then selecting all (Ctrl+A) and deleting them (Ctrl+X).

Its possible I could have resolved my issues by just deleting the specific pyc file but I never tried this

Cruciferous answered 8/8, 2014 at 8:36 Comment(0)
S
0

I faced the same problem: Import error. In addition the library've been installed 100% correctly. The source of the problem was that on my PC 3 version of python (anaconda packet) have been installed). This is why the library was installed no to the right place. After that I just changed to the proper version of python in the my IDE PyCharm.

Scimitar answered 5/12, 2015 at 7:21 Comment(0)
E
0

I had the same error. It was caused by somebody creating a folder in the same folder as my script, the name of which conflicted with a module I was importing from elsewhere. Instead of importing the external module, it looked inside this folder which obviously didn't contain the expected modules.

Eventuate answered 13/12, 2016 at 11:45 Comment(0)
R
0

In my case I was including the path to package.egg folder rather than the actual package underneath. I copied the package to top level and it worked.

Relativize answered 29/6, 2018 at 22:57 Comment(0)
B
0

This worked for me: Created __init__.py file inside parent folder (in your case, inside site-packages folder). And imported like this:

from site-packages.toolkit.interface import interface

Hope it will be useful for you as well !

Box answered 13/3, 2019 at 12:30 Comment(0)
E
0

I have a similar problem. I created a new virtual environment named python3.6.

conda create -n python3.6 python=3.6
pip install pandas

everything is ok, but when I run script, a error occurred

ModuleNotFoundError: No module named 'pandas'

I found that the metadata of the Python package and cache of pip has been updated, but it does not actually download the pandas package. so I try reinstall by pip,

pip uninstall pandas --no-cache-dir
pip install pandas 

This solved it.

Eardrum answered 12/4, 2021 at 6:59 Comment(0)
S
0

In the ubuntu apt-get installer, the python3 versions of packages are usually named

python3-XYZ

and the python2 versions

python-XYZ

As a rule of thumb, try python3-XYZ or python-XYZ of the package that is mentioned in the error message. And just guessing is not needed, search through the apt cache with a RegEx. Then:

$ apt-cache search "python.*toolkit.*interface"
python3-cli-helpers - easy command-line apps with Python
python3-exam - Python module to help write better tests
python3-fltk - Python wrapper for the Fast Light Toolkit
python3-mpltoolkits.basemap - matplotlib toolkit to plot on map projections (Python 3)
python3-nltk - Python3 libraries for natural language processing
python3-onnx - Open Neural Network Exchange (ONNX) (Python)
python3-paraview - Parallel Visualization Application. python-support
python3-pyswarms - research toolkit for particle swarm optimization in Python
python3-wxgtk-media4.0 - Python 3 interface to the wxWidgets Cross-platform C++ GUI toolkit (wx.media)
python3-wxgtk-webview4.0 - Python 3 interface to the wxWidgets Cross-platform C++ GUI toolkit (wx.html2)
python3-wxgtk4.0 - Python 3 interface to the wxWidgets Cross-platform C++ GUI toolkit
python3-xapian - Xapian search engine interface for Python3
wxglade - GUI designer written in Python with wxPython

It does not find it.

Mind that this apt-get trick will sometimes be needed for dependent packages as well or instead.

I had the same error message for the flask package for python2.7 and it vanished when I tried:

sudo apt-get install python-flask

Thus, try:

sudo apt-get install python-[YOURPYTHONVERION]-[YOURERRORPACKAGE]

or check mentioned dependencies.

Sara answered 10/12, 2021 at 23:14 Comment(0)
A
0

Using sys.path.append worked for me, as mentioned in an answer already. At first I thought it was not working until I realized I had a space before the directory path. So be sure you have no typos or spaces before you path(s)

Award answered 23/2, 2022 at 16:45 Comment(0)
E
0

The file encoding of all your python files must be utf-8.

See here: https://github.com/jupyter/notebook/issues/3166#issuecomment-581332097

Esse answered 8/4, 2022 at 16:49 Comment(0)
E
0

another cause makes this issue

file.py

#!/bin/python
from bs4 import BeautifulSoup
  • if your default python is pyyhon2
$ file $(which python)
/sbin/python: symbolic link to python2
  • file.py need python3, for this case(bs4)
  • you can not execute this module with python2 like this:
$ python file.py
# or
$ file.py
# or
$ file.py # if locate in $PATH
  • Tow way to fix this error,
# should be to make python3 as default by symlink
$ rm $(which python) && ln -s $(which python3) /usr/bin/python
# or use alias
alias python='/usr/bin.../python3'

or change shebang in file.py to

#!/usr/bin/...python3
Ezzell answered 2/8, 2022 at 23:5 Comment(0)
E
0

I had similar problem. In my case, the following thing happened:

I had a self-made package installed, and it had toolkit directory in it. Therefore, when Python looked for interface module, it searched for it not in the directory on sys.path, but in the directory of preinstalled package.

Having uninstalled this package via pip, everything got fixed for me.

Entresol answered 21/4, 2023 at 14:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.