我有一个.py文件,我想在.exe文件中转换。我使用cx_Freeze进行转换。但转换后,当我试图运行.exe文件时,它显示以下错误 -
$stream_options = array(
'http' => array(
'method' => 'GET',
),
);
$context = stream_context_create($stream_options);
$response = file_get_contents("http://api.smsbrain.in/1.2/appsms/send.php?user=username&passwd=141414&senderId=SATISH&recipients=9723613143&message=Hello", null, $context);
echo json_encode($response);
我尝试安装" queue"使用H:\Python\Practice\Download Bollywood Song\build\exe.win32-3.5>cmd /K "download_bollywood_song.exe"
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\__init__.py", line 27, in <module>
from . import urllib3
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 28, in <module>
from .packages.six.moves.queue import LifoQueue, Empty, Full
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\urllib3\packages\six.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 Files\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 12, in <module>
__import__(name + "__init__")
File "C:\Program Files\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Console.py", line 24, in <module>
exec(code, m.__dict__)
File "download_bollywood_song.py", line 10, in <module>
File "C:\Program Files\Anaconda3\lib\site-packages\requests\__init__.py", line 63, in <module>
from . import utils
File "C:\Program Files\Anaconda3\lib\site-packages\requests\utils.py", line 24, in <module>
from ._internal_utils import to_native_string
File "C:\Program Files\Anaconda3\lib\site-packages\requests\_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "C:\Program Files\Anaconda3\lib\site-packages\requests\compat.py", line 11, in <module>
from .packages import chardet
File "C:\Program Files\Anaconda3\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named 'urllib3'
H:\Python\Practice\Download Bollywood Song\build\exe.win32-3.5>
命令的模块。
但它显示以下错误 -
pip install queue
如何解决这个问题? 我在Windows 7 32位上使用python 3.5。
修改的 这是我想要转换为.exe文件的代码。
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\USER 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:\Users\USER PC>
这是我的setup.py文件代码 -
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));
答案 0 :(得分:1)
如果不在此处粘贴您的实际代码,很难说出真正的问题是什么。
请注意,在Python 3.x中,您有Queue
而不是queue
。(尝试from multiprocessing import Queue
)。正如其他simillar线程中所指定的那样,尝试:
import requests
from multiprocessing import Queue
摆脱urllib3
模块。 requests
也可以做任何你想要达到的目标。
更多,请确保您的工作目录中没有queue.py
。
作为最后的手段,我总是发现使用pyinstaller更容易。