电脑c盘内存只有2G了,安装python不安装在c盘老提示出错,python不安装在c盘安装出错跟这个有关系吗?

用Python遍历C盘dll文件的方法
投稿:goldensun
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了用Python遍历C盘dll文件的方法,用fnmatch模块实现起来非常简单,需要的朋友可以参考下
python 的还真是省心,相比于 java 中的,真是好太多了,你完成不需要去实现什么接口。
fnmatch 配合 os.walk() 或者 os.listdir() ,你能做的事太多了,而且用起来相当 easy。
# coding: utf-8
遍历C盘下的所有dll文件
import fnmatch
def main():
f = open('dll_list.txt', 'w')
for root, dirs, files in os.walk('c:\\'):
for name in files:
if fnmatch.fnmatch(name, '*.dll'):
f.write(os.path.join(root, name))
f.write('\n')
print 'done...'
if __name__=='__main__':
main()&/pre&
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具1589人阅读
python(6)
获取磁盘信息:已使用空间、总空间大小等,python没有自带的函数,常用的插件:WMI
python中自带的有获取文件夹大小、名称等信息的函数:walk()
使用wmi之前的配置
win7、win8
python2.7.7
wmi:1.4.9
pywin32:pywin32-218.win-amd64-py2.7.exe
pywin32下载地址:
注意:要下载和自己系统和所安装python版本相匹配的
因为依赖原因,在安装wmi之前需要先安装pywin32;
完成后拷贝解压后WMI-1.4.9文件夹到安装python的文件夹里面(C:/Python27/WMI-1.4.9)
然后在命令行执行:python */Python27/WMI-1.4.9/setup.py install
def get_disk_info():
:return: get the disk info
tmplist = []
c = wmi.WMI()
for physical_disk in c.Win32_DiskDrive():
tmpdict ={}
tmpdict["Caption"] = physical_disk.Caption
tmpdict["Size"] = int(physical_disk.Size)/24
tmplist.append(tmpdict)
return tmplist
def get_fs_info():
:return:get the file system info :contain partition's size ,used,avail ,operating frequency, mount info
tmplist = []
c = wmi.WMI()
for physical_disk in c.Win32_DiskDrive():
for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
tmpdict = {}
tmpdict["Caption"] = logical_disk.Caption
tmpdict["DiskTotal"] = int(logical_disk.Size)/24
tmpdict["UseSpace"]=(int(logical_disk.Size)-int(logical_disk.FreeSpace))/24
tmpdict["FreeSpace"]=int(logical_disk.FreeSpace)/24
tmpdict["Percent"]=int(100.0*(int(logical_disk.Size)-int(logical_disk.FreeSpace))/int(logical_disk.Size))
tmplist.append(tmpdict)
return tmplist
文件夹大小
fssize(dirpath):
if os.path.exists(dirpath):
if os.path.isdir(dirpath):
for root, dirs, files in os.walk(dirpath):
for name in files:
size += getsize(join(root, name))
#size += sum([getsize(join(root, name)) for name in files])
elif os.path.isfile(dirpath):
size = os.path.getsize(dirpath)
return size
至于#size += sum([getsize(join(root, name)) for name in files])
在C盘会报错:error[5],没有权限。其他盘则正常工作。
本文出自he ivy 的博客,转载请注明出处:
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:53249次
排名:千里之外
原创:36篇
(1)(3)(2)(1)(1)(3)(5)(4)(7)(18)(1)标签:至少1个,最多5个
初试爬虫之后,各种快感。然后进入到Python练习的下一阶段了——把抓取到的数据存到数据库中。再三考虑,还是决定从MySQL开始入手。虽然评论区很多倾向于SQLite及MongoDB等新潮玩意,但是MySQL还是占有决定性的市场。为了适应以后生存,这方面必须得会,就拿它先练手吧。
我的开发环境是中文win7系统32位, Python 2.7, MySQL 14.4。(Linux在虚拟机里呢,熟练之前先不挑战开发环境了-_-!)注意:这里是安装python的mysql模块,而不是mysql, 到了这一步它应该是已经安装好了的(包括MySQL Server和MySQL python connector)。
先检查自己是不是已经安装了这个模块极其简单:在Python的命令行中输入import MySQLdb,如果没有报错,那就已经安装了。
最简单的安装方法
其实就是随便找个地方按下win+R,输入cmd回车——打开windows命令行,进行著名的pip安装大法:
pip install mysql-python
按理来说,这一步足够了。但是我这出现了据说在windows环境下python安装模块的痛:命令行里返回了错误:
error: Unable to find vcvarsall.bat
然后我想到,是不是在windows用pip不太合适?所以还是循规蹈矩地到了MySQLdb的源文件,即 ()这个压缩包。随便找个地方解压缩,然后以最快的速度在cmd命令行中进入这个目录,输入:
python setup.py build
python setup.py install
按理来说,到这一步就完全成功了。不过,返回的结果是一毛一样的。。。
error: Unable to find vcvarsall.bat
然后我就知道了:其实pip安装,和我自己下载源码用python setup.py build 、 python setup.py install是一样的效果。问题源头还是在vcvarsall.bat这个东西上。一看文件名就知道是和vc相关。查询相关资料,说是经过搜索,绝大多数的回答都是:需要安装Microsoft Visual Studio2008或者2010版本,才能满足Python在windows系统上安装各种底层扩展的需要。正在下载2G的VS中。。。不过趁着下载等待时间,我在评论区发现了更easy的方法。。。。
打开页面, 是这个模样:满屏幕毫无美感的英文,连排版都没有,真有点不太好接受。不过趁着VS还没下载完,就简单读了读,发现了第二行关键词:University of California, Irvine.,原来是加大的作品啊,一看就是科学家制作,比较大气,耐着心读了读说明段落——好像是专门针对windows对python支持性差做的工作——把python扩展都制作成了二进制文件,即.whl文件。
安装二进制的Python扩展包
看起来好像是个好东西,就ctrl+f查找mysql,还真找到了!
MySQL-python, a Python database API 2.0 interface for the MySQL database
Mysqlclient is a Python 3 compatible fork of MySQL-python.MySQL_python-1.2.5-cp27-none-win32.whlMySQL_python-1.2.5-cp27-none-win_amd64.whl
选择win32.whl这个文件下载,才772k。但是这个whl文件格式怎么安装呢?回到网页上面,发现说了是用pip安装,于是我在这个目录打开cmd命令行,输入:哈哈,献丑了!whl文件的安装方法,在pip的官方文档里说明的很清楚()所以再来了一遍:输入:
pip install MySQL_python-1.2.5-cp27-none-win32.whl
返回:Processing c:\tdownload\mysql\mysql_python-1.2.5-cp27-none-win32.whlInstalling collected packages: MySQL-pythonSuccessfully installed MySQL-python-1.2.5
安装成功!
到Python里面试了一下import MySQLdb,也正常!于是乎,我觉得写文章的这个功夫,已经下载好的Microsoft Visual Studio也没必要了。。。。
2 收藏&&|&&9
你可能感兴趣的文章
本作品采用 署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
安装talib也是碰到同样问题,终于在这里找到解决问题方法了。根据stackoverflow,下载VS2015,设置环境变量之后还是不行。然后还是下载了二进制文件才安装成功。
楼主为什么我按照这种方法不行呢
吆西,完美解决
分享到微博?
技术专栏,帮你记录编程中的点滴,提升你对技术的理解收藏感兴趣的文章,丰富自己的知识库
明天提醒我
我要该,理由是:
扫扫下载 AppPython实现获取磁盘剩余空间的2种方法
作者:天飞
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了Python实现获取磁盘剩余空间的2种方法,结合具体实例形式分析了Python操作计算机硬件的相关实现技巧,需要的朋友可以参考下
本文实例讲述了Python实现获取磁盘剩余空间的2种方法。分享给大家供大家参考,具体如下:
import ctypes
import platform
import sys
def get_free_space_mb(folder):
""" Return folder/drive free space (in bytes)
if platform.system() == 'Windows':
free_bytes = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
return free_bytes.value/24
st = os.statvfs(folder)
return st.f_bavail * st.f_frsize/
print(get_free_space_mb('C:\\'),'GB')
import win32com.client as com
def TotalSize(drive):
""" Return the TotalSize of a shared drive [GB]"""
fso = com.Dispatch("Scripting.FileSystemObject")
drv = fso.GetDrive(drive)
return drv.TotalSize/2**30
def FreeSpace(drive):
""" Return the FreeSpace of a shared drive [GB]"""
fso = com.Dispatch("Scripting.FileSystemObject")
drv = fso.GetDrive(drive)
return drv.FreeSpace/2**30
workstations = ['dolphins']
print ('Hard drive sizes:')
for compName in workstations:
drive = '\\\\' + compName + '\\c$'
print ('*************************************************\n')
print (compName)
print ('TotalSize of %s = %f GB' % (drive, TotalSize(drive)))
print ('FreeSpace on %s = %f GB' % (drive, FreeSpace(drive)))
print ('*************************************************\n')
运行效果如下图:
更多关于Python相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家Python程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具使用Python获取CPU、内存和硬盘等windowns系统信息的2个例子
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了使用Python获取CPU、内存和硬盘等windowns系统信息的2个例子,使用的python wmi模块,需要的朋友可以参考下
Python用WMI模块获取windowns系统的硬件信息:硬盘分区、使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息。
代码如下:#!/usr/bin/env python # -*- coding: utf-8 -*- import wmi import os import sys import platform import time def sys_version():& &&& c = wmi.WMI () &&& #获取操作系统版本 &&& for sys in c.Win32_OperatingSystem(): &&&&&&& print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber &&&&&&& print& sys.OSArchitecture.encode("UTF8")#系统是32位还是64位的 &&&&&&& print sys.NumberOfProcesses #当前系统运行的进程总数def cpu_mem(): &&& c = wmi.WMI ()&&&&&&& &&& #CPU类型和内存 &&& for processor in c.Win32_Processor(): &&&&&&& #print "Processor ID: %s" % processor.DeviceID &&&&&&& print "Process Name: %s" % processor.Name.strip() &&& for Memory in c.Win32_PhysicalMemory(): &&&&&&& print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/1048576) def cpu_use(): &&& #5s取一次CPU的使用率 &&& c = wmi.WMI() &&& while True: &&&&&&& for cpu in c.Win32_Processor(): &&&&&&&&&&&& timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime()) &&&&&&&&&&&& print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage) &&&&&&&&&&&& time.sleep(5)&&&& def disk(): &&& c = wmi.WMI ()&&& &&& #获取硬盘分区 &&& for physical_disk in c.Win32_DiskDrive (): &&&&&&& for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"): &&&&&&&&&&& for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"): &&&&&&&&&&&&&&& print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption &&& #获取硬盘使用百分情况 &&& for disk in c.Win32_LogicalDisk (DriveType=3): &&&&&&& print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size)) def network(): &&& c = wmi.WMI ()&&&& &&& #获取MAC和IP地址 &&& for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1): &&&&&&& print "MAC: %s" % interface.MACAddress &&& for ip_address in interface.IPAddress: &&&&&&& print "ip_add: %s" % ip_address &&& print &&& #获取自启动程序的位置 &&& for s in c.Win32_StartupCommand (): &&&&&&& print "[%s] %s &%s&" % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s.Command.encode("UTF8"))& &&&& &&& #获取当前运行的进程 &&& for process in c.Win32_Process (): &&&&&&& print process.ProcessId, process.Name def main(): &&& sys_version() &&& #cpu_mem() &&& #disk() &&& #network() &&& #cpu_use() if __name__ == '__main__': &&& main() &&& print platform.system() &&& print platform.release() &&& print platform.version() &&& print platform.platform() &&& print platform.machine()
由于我用到的不多,所以只获取的CPU、内存和硬盘,如果需要其它资源,请参照msdn。
代码如下:import osimport win32apiimport win32conimport wmiimport time
def getSysInfo(wmiService = None):&&& result = {}&&& if wmiService == None:&&&&&&& wmiService = wmi.WMI()&&& # cpu&&& for cpu in wmiService.Win32_Processor():&&&&&&& timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())&&&&&&& result['cpuPercent'] = cpu.loadPercentage&&& # memory&&& cs = wmiService.Win32_ComputerSystem()&&& os = wmiService.Win32_OperatingSystem()&&& result['memTotal'] = int(int(cs[0].TotalPhysicalMemory)/)&&& result['memFree'] = int(int(os[0].FreePhysicalMemory)/1024)&&& #disk&&& result['diskTotal'] = 0&&& result['diskFree'] = 0&&& for disk in wmiService.Win32_LogicalDisk(DriveType=3):&&&&&&& result['diskTotal'] += int(disk.Size)&&&&&&& result['diskFree'] += int(disk.FreeSpace)&&& result['diskTotal'] = int(result['diskTotal']/)&&& result['diskFree'] = int(result['diskFree']/)&&& return result
if __name__ == '__main__':&&& wmiService = wmi.WMI()&&& while True:&&&&&&& print getSysInfo(wmiService)&&&&&&& time.sleep(3)
采用的wmi模块获取的,由于wmi初始化时占用系统资源太高,所以如果需要循环获取,请在循环体外面把wmi对象初始化好,然后传入函数里面,这样就不会产生CPU资源过高的情况。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具}

我要回帖

更多关于 python安装在c盘 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信