|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
最近惨遭困扰,网上下载了一个代码,但是发现用不了
代码如下:
# 更改文件编码
# 文件统一改为utf-8无BOM
# -*- coding: UTF-8 -*-
import os
import pandas as pd
#需要把文件改成编码的格式(可以自己随时修改)
coding = 'utf-8_sig'
# 文件夹目录(可以更改文件编码的文件夹~)
file_dir = '/Users/mac/Documents/Microsoft\ 用户数据/python-Folder/更改文件编码为utf-8'
def run_coding():
for root, dirs, files in os.walk(file_dir, topdown=False):
for i in files:
files_name = os.path.join(root, i)
try:
df1 = pd.read_csv(files_name, encoding='utf-8')
except:
df1 = pd.read_csv(files_name, encoding='gbk')
df1.to_csv(files_name, encoding=coding,index=None)
if __name__ == '__main__':
run_coding()
print("It's done")
运行之后提示“ModuleNotFoundError: No module named 'pandas'”,搜索后都是建议要下载pandas,嗯按操作“pip install pandas”后安装了,但是还是提示同样的错误,再安装就发现:
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pandas in ./Library/Python/2.7/lib/python/site-packages (0.24.2)
Requirement already satisfied: numpy>=1.12.0 in ./Library/Python/2.7/lib/python/site-packages (from pandas) (1.16.6)
Requirement already satisfied: python-dateutil>=2.5.0 in ./Library/Python/2.7/lib/python/site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2011k in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas) (2013.7)
Requirement already satisfied: six>=1.5 in ./Library/Python/2.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.14.0)
求教,这个是说明安装在了2.7的目录下吗?但是我切换默认程序为3.8的以后还是不行:
【
Mac修改默认Python版本
1.安装Python 3
2.查看Python3 安装路径
打开终端,输入which python3,查看路径 /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
3.打开配置文件
open ~/.bash_profile
4.写入外部环境变量
export PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
5.重命名Python
alias python="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
6.关闭文件
7.终端执行命令:source ~/.bash_profile
8.终端执行命令: python检查Python版本
】
所以求请教:MAC 怎么卸载掉自带的Python2.7,只留python3?不然的话我好像一直会装不了python的各种常用库。新手求教
mac系统基于linux内核 现在所有linux发行版都是预装了python2.7 如果你卸载掉可能会出问题
一般Linux都是双版本共存的 做软连接
|
|