python-2.7

Failure to build wheel / “Error: INCLUDE Environment Variable is empty”

假如想象 提交于 2021-02-07 13:20:30
问题 I am using Python 2.7.11 and am trying to pip install modules however a few of them are failing. The message I get is "Failure to build wheel for 'X'" and "Error: INCLUDE Environment Variable is empty". I tried to install Scrapy, LXML and Twisted and those failed. Some other random modules I tried installed fine. I have installed pyOpenSSL, added python27 and python27/scripts to environment. Thanks, 回答1: I tried both the solutions offered, none worked. I installed Microsoft Visual C++

Please what does func() mean in python when used inside a function

邮差的信 提交于 2021-02-07 12:26:40
问题 Please what does func() mean in python when used inside a function,For example in the code below. def identity_decorator(func): def wrapper(): func() return wrapper 回答1: func is an argument given to the function identity_decorator() . The expression func() means "call the function assigned to the variable func ." The decorator is taking another function as an argument, and returning a new function (defined as wrapper ) which executes the given function func when it is run. Here is some

why does python socket library not include recvall() method like sendall()?

家住魔仙堡 提交于 2021-02-07 11:27:16
问题 When using recv() method, sometimes we can't receive as much data as we want, just like using send(). But we can use sendall() to solve the problem of sending data, how about receiving data? Why there is no such recvall() method? 回答1: There is no fundamental reason why such a function could not be provided as part of the standard library. In fact, there has been at least one attempt to add recvall(). Given that it can be easily implemented as a loop around recv() , I don't think that this is

How to get only files in directory? [duplicate]

佐手、 提交于 2021-02-07 11:18:18
问题 This question already has answers here : How do I list all files of a directory? (21 answers) Closed 7 years ago . I have this code: allFiles = os.listdir(myPath) for module in allFiles: if 'Module' in module: #if the word module is in the filename dirToScreens = os.path.join(myPath, module) allSreens = os.listdir(dirToScreens) Now, all works well, I just need to change the line allSreens = os.listdir(dirToScreens) to get a list of just files, not folders. Therefore, when I use allScreens [ f

How to get only files in directory? [duplicate]

安稳与你 提交于 2021-02-07 11:17:48
问题 This question already has answers here : How do I list all files of a directory? (21 answers) Closed 7 years ago . I have this code: allFiles = os.listdir(myPath) for module in allFiles: if 'Module' in module: #if the word module is in the filename dirToScreens = os.path.join(myPath, module) allSreens = os.listdir(dirToScreens) Now, all works well, I just need to change the line allSreens = os.listdir(dirToScreens) to get a list of just files, not folders. Therefore, when I use allScreens [ f

Scraping images using beautiful soup

这一生的挚爱 提交于 2021-02-07 10:53:47
问题 I'm trying to scrape the image from an article using beautiful soup. It seems to work but I can't open the image. I get a file format error every time I try to access the image from my desktop. Any insights? timestamp = time.asctime() # Parse HTML of article, aka making soup soup = BeautifulSoup(urllib2.urlopen(url).read()) # Create a new file to write content to txt = open('%s.jpg' % timestamp, "wb") # Scrape article main img links = soup.find('figure').find_all('img', src=True) for link in

Opening a plot in tkinter only (no matplotlib popup)

孤者浪人 提交于 2021-02-07 10:24:42
问题 I am opening a matplotlib pyplot in a tkinter window with the below code. My issue is that the plot is still popping up in the matplotlib window as well, and I don't know how to stop that. I've tried commenting out each of the plt.plot's but that didn't help. import numpy as np import matplotlib.pyplot as plt import matplotlib matplotlib.use('TkAgg') from numpy import arange, sin, pi from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib

Opening a plot in tkinter only (no matplotlib popup)

為{幸葍}努か 提交于 2021-02-07 10:23:32
问题 I am opening a matplotlib pyplot in a tkinter window with the below code. My issue is that the plot is still popping up in the matplotlib window as well, and I don't know how to stop that. I've tried commenting out each of the plt.plot's but that didn't help. import numpy as np import matplotlib.pyplot as plt import matplotlib matplotlib.use('TkAgg') from numpy import arange, sin, pi from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib

sklearn grid.fit(X,y) - error: “positional indexers are out-of-bounds” for X_train,y_train

人走茶凉 提交于 2021-02-07 10:11:26
问题 This is a question about scikit learn (version 0.17.0) in Python 2.7 along with Pandas 0.17.1. In order to split raw data (with no missing entries) using the approach detailed here, I have found that if the split data are used to proceed with a .fit() that there is an error that appears. Here is the code taken largely unchanged from the other stackoverflow question with renaming of variables. I have then instantiated a grid and tried to fit the split data with the aim of determining optimal

How to use subprocess.Popen with built-in command on Windows

 ̄綄美尐妖づ 提交于 2021-02-07 10:01:07
问题 In my old python script, I use the following code to show the result for Windows cmd command: print(os.popen("dir c:\\").read()) As the python 2.7 document said os.popen is obsolete and subprocess is recommended. I follow the documentation as: result = subprocess.Popen("dir c:\\").stdout And I got error message: WindowsError: [Error 2] The system cannot find the file specified Can you tell me the correct way to use the subprocess module? 回答1: You should use call subprocess.Popen with shell