新手求教:MAC 怎么卸载掉自带的Python2.7,只留python3
最近惨遭困扰,网上下载了一个代码,但是发现用不了代码如下:
# 更改文件编码
# 文件统一改为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都是双版本共存的 做软连接 用电脑管家强力卸载 卸载自带2.7,系统会出问题的,一般是在/usr/bin下创建python3软链接,指向你安装的python3版本,然后你写的代码第一行这样写:
#! /usr/bin/python3
第二行是声明文件编码 admintest166 发表于 2020-4-7 14:53
mac系统基于linux内核 现在所有linux发行版都是预装了python2.7 如果你卸载掉可能会出问题
一般Linux都 ...
你好,我也是搜到有说法是删掉可能会有问题。python3.8我是已经在用了的,算是双版本共存吗?但是库都是装在2.7上,导致我在用IDLE的时候用不了库,这种情况要怎么解决好呢
也许这个网址能帮到你(由于找不到MACos系统的,所以找了个Linux系统的):https://www.v2ex.com/t/582104
还有,我以前在Linux系统卸载过python2.7,没有报错{:10_256:}但不知道MacOS系统... 你装上去py3没用啊 你运行python还是python2.7 linux装python3必须要做软连接但是mac可能不一样(没用过) 我centos和ubantu都是要做软连接的
你参考这个看下吧 https://www.cnblogs.com/igoodful/p/11788631.html admintest166 发表于 2020-4-7 17:15
你装上去py3没用啊 你运行python还是python2.7 linux装python3必须要做软连接但是mac可能不一样(没用 ...
忘了之前是怎么安装的,现在用IDLE打开都是3.8的版本哦 我的需求在这个链接里被解决了,就是怎么在双版本下,把库装在我需要的版本里面,在pip install XXX之前加上指定版本就可以了。
例如python3 -m pip install pandas
谢谢大家。
在python2和python3同时存在的情况下,如何使用pip安装指定版本的包(Ubuntu系统):https://blog.csdn.net/qq_33278989/article/details/80371349 NatOliver 发表于 2020-4-7 19:31
我的需求在这个链接里被解决了,就是怎么在双版本下,把库装在我需要的版本里面,在pip install XXX之前加 ...
这样我也不需要删掉2.7了{:5_109:}
页:
[1]