python中一些常用的配置

一些常用设置

pandas 设置 Dataframe 表格显示全部的行,全部列以及每个单元格中的全部内容

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)

jupyter 创建内核

在这里插入图片描述

  • 如果已经创建了 conda 环境
  • 那么首先使用这个 conda 环境:
    conda activate your_env_name
  • 在这个环境下创建 ipykernel :
    pip install ipykernel
  • 通过 ipykernel 创建 jupyter 对应的内核:
    python -m ipykernel install --user --name your_env_name

如果内核不能自动补全

  • 首先配置 Nbextension

    pip install jupyter_contrib_nbextensions

    jupyter contrib nbextension install --user

    pip install jupyter_nbextensions_configurator

    在这里插入图片描述
    在这里插入图片描述

  • 如果弄完了补全还是不行
    参考

pycharm terminal 显示自动换行

清华镜像源

https://pypi.tuna.tsinghua.edu.cn/simple 

python常用代码库

中文繁体简体转换

https://zhon.readthedocs.io/en/latest/#using-zhon

jieba 和 NLTK

https://www.osgeo.cn/python-tutorial/nltk-intro.html

常见错误

TypeError: unhashable type: 'list'
  • 这意思就是 dict 类型的 key 用了一个不可哈希的变量,例如列表

pytorch 1.8 gpu 安装

pytorch 过去版本的安装

pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

在 python 脚本文件中嵌入 pip 安装命令

  • 让文件一运行就自动安装某些包

首先创建一个 requirements.txt

  • requirements.txt 中放好你想要安装的package 的名称,版本,想使用的源
  • 如果不想使用任何额外的源,就把 -i 后面的部分删去
torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
Flask==2.1.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
jieba==0.42.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
numpy==1.21.6 -i https://pypi.tuna.tsinghua.edu.cn/simple
rouge==1.0.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
tqdm==4.64.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
transformers==4.15.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

然后调用 sys 来执行安装命令

import os
with open("./requirements.txt", 'r') as f:
        lines = f.readlines()
for line in lines:
    cmd = f'pip install {line}'
    print(cmd)
    # cmd='pip install -r ./requirements.txt'
    os.system(cmd)
  • 保险起见,将上述代码放在执行入口文件的第一行。

python 获取递归深度和更改递归深度

import sys
sys.getrecursionlimit()
sys.setrecursionlimit(100000)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暖仔会飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值