python - Fejl konvertere .py-fil til .exe-fil ved hjælp af cx\_Freeze

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg har en .py-fil, som jeg vil konvertere til .exe-fil. Jeg brugte cx\_Freeze til at konvertere det. Men efter konvertering, når jeg prøver at køre .exe-filen, viser den følgende fejl-


H:PythonPracticeDownload Bollywood Songuildexe.win32-3.5>cmd /K "download\_bollywood\_song.exe"
Traceback (most recent call last):
  File "C:Program FilesAnaconda3libsite-packages
equestspackages\_\_init\_\_.py", line 27, in <module>
from . import urllib3
  File "C:Program FilesAnaconda3libsite-packages
equestspackagesurllib3\_\_init\_\_.py", line 8, in <module>
from .connectionpool import (
  File "C:Program FilesAnaconda3libsite-packages
equestspackagesurllib3connectionpool.py", line 28, in <module>
from .packages.six.moves.queue import LifoQueue, Empty, Full
  File "C:Program FilesAnaconda3libsite-packages
equestspackagesurllib3packagessix.py", line 203, in load\_module
mod = mod.\_resolve()
  File "C:Program FilesAnaconda3libsite-packages
equestspackagesurllib3packagessix.py", line 115, in \_resolve
return \_import\_module(self.mod)
  File "C:Program FilesAnaconda3libsite-packages
equestspackagesurllib3packagessix.py", line 82, in \_import\_module
\_\_import\_\_(name)
ImportError: No module named 'queue'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:Program FilesAnaconda3libsite-packagescx\_Freezeinitscripts\_\_startup\_\_.py", line 12, in <module>
\_\_import\_\_(name + "\_\_init\_\_")
  File "C:Program FilesAnaconda3libsite-packagescx\_FreezeinitscriptsConsole.py", line 24, in <module>
exec(code, m.\_\_dict\_\_)
  File "download\_bollywood\_song.py", line 10, in <module>
  File "C:Program FilesAnaconda3libsite-packages
equests\_\_init\_\_.py", line 63, in <module>
from . import utils
  File "C:Program FilesAnaconda3libsite-packages
equestsutils.py", line 24, in <module>
from .\_internal\_utils import to\_native\_string
  File "C:Program FilesAnaconda3libsite-packages
equests\_internal\_utils.py", line 11, in <module>
from .compat import is\_py2, builtin\_str, str
  File "C:Program FilesAnaconda3libsite-packages
equestscompat.py", line 11, in <module>
from .packages import chardet
  File "C:Program FilesAnaconda3libsite-packages
equestspackages\_\_init\_\_.py", line 29, in <module>
import urllib3
ImportError: No module named 'urllib3'

H:PythonPracticeDownload Bollywood Songuildexe.win32-3.5>


Jeg forsøgte at installere 'kø' -modul ved hjælp af kommandoen pip install queue.
Men det viser følgende fejl-


Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:UsersUSER PC>pip install queue
Collecting queue
  Could not find a version that satisfies the requirement queue (from versions: )
No matching distribution found for queue

C:UsersUSER PC>


Sådan løser du dette problem ??
Jeg bruger python 3.5 på Windows 7 32 bit.


Rediger
Her er min kode, som jeg vil konvertere til .exe-fil.


import time;
import requests;
from bs4 import BeautifulSoup;

def get\_page(url):

    response = requests.get(url);
    html = response.text;
    return html;

def make\_soup(html):

    soup = BeautifulSoup(html,"html.parser");
    return soup;

def get\_movie\_link(words):

    movie\_name = "";
    first = True;

    for word in words:
        if(not first):
            movie\_name+=" ";
        first = False;
        movie\_name+=word;

    movie\_link = "";
    movie\_name = movie\_name.title();
    first\_character = movie\_name[0];

    url = "http://songsmp3.co/1/bollywood-music/list-" + first\_character + ".html";
    html = get\_page(url);
    soup = make\_soup(html);
    movie\_list = soup.find\_all("div",class\_="list\_inside\_box");
    movies = [];

    for movie in movie\_list:
        movies = movie.find\_all("a");
    for movie in movies:
        name = movie.get\_text();
        link = movie.get("href");
        if(name.find(movie\_name) > -1):
            movie\_link = link;
            break;
    return movie\_name,movie\_link;

def get\_download\_link(movie\_name,movie\_link):

    if(movie\_link == ""):
        return movie\_link;
    if(movie\_link.find("http://songsmp3.co") == -1):
        movie\_link = "http://songsmp3.co" + movie\_link;

    html = get\_page(movie\_link);
    soup = make\_soup(html);
    links = soup.find\_all("div",class\_="link-item-zip");

    download\_link = "";
    for link in links:
        data = link.find("a");
        song\_link = data.get("href");
        if(download\_link == ""):
            download\_link = song\_link;

    return download\_link;

def download\_songs(movie\_name,download\_link):

    if(download\_link == ""):
        return;

    file\_name = movie\_name + ".zip";
    response = requests.get(download\_link, stream=True);
    file = open(file\_name, "wb");
    file.write(response.content);
    file.close();
    return;

start\_time = time.clock();
#print("N.B: Becareful about spelling.");
words = input().split();

movie\_name,movie\_link = get\_movie\_link(words);
download\_link = get\_download\_link(movie\_name,movie\_link);
download\_songs(movie\_name,download\_link);

end\_time = time.clock();
print("Execution Time: \%.2f"\%(end\_time-start\_time));


Og her er min setup.py filkode-


from cx\_Freeze import setup, Executable;

setup(name="Download Bollywood Song",version="1.0.1",description="Download specified movie songs",
      executables=[Executable("download\_bollywood\_song.py")]);

Bedste reference


Det er svært at fortælle, hvad det virkelige problem er uden at indsætte din aktuelle kode her.


Bær med, at i Python 3.x har du Queue i stedet for queue. (Prøv from multiprocessing import Queue). Som angivet i andre simillar tråde, prøv at gøre:


import requests
from multiprocessing import Queue


Og slippe af med urllib3 modulet. requests kan gøre hvad du også forsøger at opnå.


Mere, sørg for at du ikke har nogen queue.py i din arbejdskatalog.


Som en sidste udvej har jeg altid fundet det nemmere at arbejde med pyinstaller. [13]