简体   繁体   中英

pyinstaller ImportError error - how to solve it?

I have installed pyinstaller in my Linux in order to create an executable to my Python script, which runs normaly with the command:

python3 exemplo.py

However when I execute bellow command:

pyinstaller --onefile example.py

I get the following error:

File "/home/pedro/.local/bin/pyinstaller", line 11, in <module>
     sys.exit(run())   File "/home/pedro/.local/lib/python2.7/site-packages/PyInstaller/__main__.py",
line 79, in run
    import PyInstaller.building.build_main   File "/home/pedro/.local/lib/python2.7/site-packages/PyInstaller/building/build_main.py",
line 33, in <module>
   from ..depend import bindepend   File "/home/pedro/.local/lib/python2.7/site-packages/PyInstaller/depend/bindepend.py",
line 26, in <module>
    from . import dylib, utils   File "/home/pedro/.local/lib/python2.7/site-packages/PyInstaller/depend/utils.py",
line 25, in <module>
     from ..lib.modulegraph import util, modulegraph   File "/home/pedro/.local/lib/python2.7/site-packages/PyInstaller/lib/modulegraph/util.py",
line 16, in <module>
     from ._compat import StringIO, BytesIO, get_instructions, _READ_MODE   File "/home/pedro/.local/lib/python2.7/site-packages/PyInstaller/lib/modulegraph/_compat.py",
line 29, in <module>
     from dis3 import get_instructions ImportError: No module named dis3

What is wrong?

I tried to install dis3:

python3 -m pip install --user dis3

But I still get the same error.

I uninstalled it ...

python -m pip uninstall pyinstaller

Installed again as recommended.

python3 -m pip install --user pyinstaller

I have set the PATH variable:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/home/pedro/.local/bin

Now I get the message:

pedro@pedro-pc:~/Documents/instabot/instabot_c.py$ python -m pyinstaller --onefile example.py
/usr/bin/python: No module named pyinstaller

Indeed ... it does not appear on pip list:

pedro@pedro-pc:~/Documents/instabot/instabot_c.py/__pycache__$ pip list
/home/pedro/.local/lib/python2.7/site-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
Package        Version               
-------------- ----------------------
altgraph       0.16.1                
arandr         0.1.9                 
beautifulsoup4 4.4.1                 
certifi        2018.10.15            
chardet        3.0.4                 
cryptography   1.2.3                 
defer          1.0.6                 
enum34         1.1.2                 
fake-useragent 0.1.11                
future         0.17.1                
html5lib       0.999                 
idna           2.7                   
ipaddress      1.0.16                
lxml           3.5.0                 
macholib       1.11                  
numpy          1.11.0                
pefile         2018.8.8              
pip            18.1                  
psutil         3.4.2                 
pyasn1         0.1.9                 
pycurl         7.43.0                
Pygments       2.1                   
pygobject      3.20.0                
pyOpenSSL      0.15.1                
pysqlite       2.7.0                 
python-apt     1.1.0b1+ubuntu0.16.4.2
python-debian  0.1.27                
pyxdg          0.25                  
requests       2.20.0                
scour          0.32                  
setuptools     20.7.0                
six            1.10.0                
urllib3        1.24                  
wheel          0.29.0   

What is wrong?

your project is python3 but pyinstaller running on python2.7 remove the package from 2.7 install for python3

uninstall pyinstaller from python2.7

pip uninstall pyinstaller

install pyintaller for python3

pip3 install pyinstaller

if you wanna put this package for both python2.7 and 3 this code run pyinstaller on python3

python3 -m pyinstaller --onefile example.py

pip and pip3 will invoke different python interpreters (2.7 and 3 respectively).

Similarly python and python3 are different too, if you used "pip3 install pyinstaller" and now you're calling "python -m pyinstaller", your interpreter is searching for pyinstaller in the pip list! Instead you want to do "python3 -m pyinstaller" and then it should work.

When you used:

pyinstaller --onefile example.py

Your pyinstaller was installed in python2.7 using pip, and so it couldn't find a module named dis3 which you probably have in your pip3 list (python3).

Here's another way to set up pyinstaller so that you can directly use "pyinstaller yourfile.py" in linux.

1) git clone https://github.com/pyinstaller/pyinstaller

2) cd pyinstaller, then cd into bootloader

3) Run “python3 ./waf distclean all” to build the bootloader for your system.

4) Once the bootloader has been built, type in: “python3 setup.py install”

5) This should have installed pyinstaller. Type pyinstaller in the terminal and hit enter. It should recognize the command, but it will complain about more arguments.

6) Use the command "pyinstaller yourfile.py" to create your executable.

If you want to create a stand-alone one file executable use: "pyinstaller --onefile yourfile.py"

Hope this helps!

我按照此链接的说明进行操作: Python问题它解决了我提到的最后一个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM