标签 python 下的文章

安装

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

sh Miniconda3-latest-Linux-x86_64.sh

一路yes即可安装完成,完成后source ~/.zshrc或者source ~/.bashrc生效。

# shell自动加载
conda config --set auto_activate_base false
# 回滚
conda init --reverse $SHELL

初始化环境

创建环境

conda create --name myenv python=3.11

创建后不是默认生效的,需要执行conda activate myenv生效,如果需要默认生效则需要加入到~/.zshrc中:

echo "conda activate myenv" >>~/.zshrc

删除环境

conda remove --name myenv --all

安装包

conda install package_name

更新包

conda update package_name

查看已安装的package

conda list

更新conda

conda update conda

import time


# 进度条打印函数
def print_progress_bar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='=', print_end="\r"):
    """
    Call in a loop to create terminal progress bar
    @params:
        iteration   - Required  : current iteration (Int)
        total       - Required  : total iterations (Int)
        prefix      - Optional  : prefix string (Str)
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
        print_end    - Optional  : end character (e.g. "\r", "\r\n") (Str)
    """
    percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
    filled_length = int(length * iteration // total)
    bar = fill * filled_length + ">" + '-' * (length - filled_length)
    print(f'\r{prefix} |{bar}| {percent}% {suffix}', end=print_end)
    # Print New Line on Complete
    if iteration == total:
        print()


if __name__ == '__main__':
    for i in range(1, 11):
        print_progress_bar(i, 10, "Progress: ", )
        time.sleep(0.2)

使用logging模块打印日志的时候遇到错误:

Traceback (most recent call last):
  File "saas_utils.py", line 106, in <module>
    sangfor_login("192.168.10.1", login_user, login_pwd)
  File "saas_utils.py", line 72, in sangfor_login
    logging.INFO("%s: %s" % (type(cookie_str), cookie_str))
TypeError: 'int' object is not callable

网上查了一下,出现这个问题的原因是函数或者变量命名错误了,但是检查了一下没有发现有重复的函数和变量名。

后面仔细推敲了一下才发现函数名字写错了,logging.info被我写成了loggin.INFOloggin.INFO是日志的调试级别,当成函数使用当然报错了。

一、setuptools安装错误:RuntimeError: Compression requires the (missing) zlib module

1. 描述

搞了个腾讯云的服务器,闲在手上没事准备当个测试机用用,写写代码什么的。然后按照之前写的文章安装了python2.7 ,安装的中途出现了一个错误:

running install
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file "setuptools.egg-info/SOURCES.txt"
reading manifest template "MANIFEST.in"
warning: no files found matching "*" under directory "setuptools/_vendor"
writing manifest file "setuptools.egg-info/SOURCES.txt"
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating "dist/setuptools-36.6.0-py2.7.egg" and adding "build/bdist.linux-x86_64/egg" to it
Traceback (most recent call last):
  File "setup.py", line 188, in <module>
    dist = setuptools.setup(**setup_params)
  File "/usr/local/python27/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/local/python27/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/python27/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/data/setuptools-36.6.0/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/data/setuptools-36.6.0/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command("bdist_egg")
  File "/usr/local/python27/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/local/python27/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/data/setuptools-36.6.0/setuptools/command/bdist_egg.py", line 231, in run
    dry_run=self.dry_run, mode=self.gen_header())
  File "/data/setuptools-36.6.0/setuptools/command/bdist_egg.py", line 473, in make_zipfile
    z = zipfile.ZipFile(zip_filename, mode, compression=compression)
  File "/usr/local/python27/lib/python2.7/zipfile.py", line 736, in __init__
    "Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module

- 阅读剩余部分 -