a2.sqlalchemy-操作

本文详细介绍了SQLAlchemy中的查询操作,包括基本查询、聚合函数、反向查询和数据批量操作。内容涵盖filter与filter_by的区别,查看SQL语句的方法,order_by、limit、offset、slice等操作,以及聚合函数如count、sum、max、min的使用。同时讨论了数据的批量插入、删除,反向查询和特殊场景下的处理策略。

一、sqlalchemy中的查询分析

1、基本查询

filter和filter_by的区别:

  • filter可以在后边加判断条件,但是每次只能过滤一个条件
  • filter_by可以过滤多个,与Django的orm的方式类似,但是只能用“=”

如何查看sqlalchemey的sql语句

在不添加结尾的all()``first()等,得到的具体查询对象,直接利用str方法,便可将其转换为sql语句

row = session.query(User).filter(User.username!='aaa')
print(row)

结果

SELECT user.id AS user_id, user.username AS user_username, user.password AS user_password, user.createtime AS user_createtime, user._locked AS user__locked 
FROM user 
WHERE user.username != %(username_1)s

表中单个字段查询

print(session.query(User.username).filter(User.username!='dandan').all())

first()

仅查询显示第一个

print(session.query(User.username).filter(User.username!='dandan').first())

one()

只查询出来第一个,有且只有一个
如果有两个符合条件的,会报错

print(session.query(User).filter(User.username=='choupi').one())

结果

<User(id='12' ,username='choupi',password='q1',createtime='2018-03-09 20:27:54',_locked ='False',)>

get 根据主键查询

主键在表中只有一个
例如ID为主键,查询id=3的元素

print(session.query(User).get(3))
# 结果
<User(id='3' ,username='tree',password='zzz111',createtime='2018-03-09 14:44:21',_locked ='False',)>

limit 限制查询结果

limit(3) 仅查出3条结果

print(session.query(User).filter(User.username!='dandan').limit(3).all())
# 结果
[<User(id='2' ,username='tobee',password='234qwe',createtime='2018-03-07 16:16:05',_locked ='False',)>, <User(id='3' ,username='tree',password='zzz111',createtime='2018-03-09 14:44:21',_locked ='False',)>, <User(id='4' ,username='aaa',password='111',createtime='2018-03-09 17:57:15',_locked ='False',)>]

offset() 限制前面n个,显示后面n+1个,向后便宜Nge

显示第N个以后

print(session.query(User.username).filter(User.username!='dandan').all())
print(session.query(User.username).filter(User.username!='dandan').limit(3).all())

print(session.query(User.username).filter(User.username!='dandan').offset(3).all())

结果:

[('tobee',), ('tree',), ('aaa',), ('coding',), ('choupi',), ('111',), ('choupidan',), ('youku',)]
[('tobee',), ('tree',), ('aaa',)]
[('coding',), ('choupi',), ('111',), ('choupidan',), ('youku',)]

slice() 切片,也可以直接使用[1,9]

slice(1,3) 与python的slice一致,从0开始 左闭右开,显示1,2两个元素

print(session.query(User.username).filter(User.username!='dandan').slice(1,3).all())
# 结果
[('tree',), ('aaa',)]

order_by() 元素排序 顺序

print(session.query(User.username).filter(User.username!='dandan').order_by(User.username).all())

# 按数字字符顺序排序

[('111',), ('aaa',), ('choupi',), ('choupidan',), ('coding',), ('tobee',), ('tree',), ('youku',)]

desc() 逆序排序

from sqlalchemy import desc
print(session.query(User.username).filter(User.username!='dandan').order_by(desc(User.username)).all())

# 逆序排序

[('youku',), ('tree',), ('tobee',), ('coding',), ('choupidan',), ('choupi',), ('aaa',), ('111',)]

like() 模糊搜索,结合占位符%使用 与原生sql一致

print(session.query(User.username).filter(User.username.like('%e')).all())
# 结果
[('tobee',), ('tree',)]

ilike() 模糊搜索,不区分大小写

# 内部实现如下类似操作:
lower(a) LIKE lower(other)
# 同理还有 notilike() 方法,
# 跟like()用法一致,只是不区分大小写。
# 这个是sqlalchemy ORM 层做的强化,不是数据库层的用法

notlike()

print(session.query(User.username).filter(User.username.notlike('%e')).all())
# 结果
[('dandan',), ('aaa',), ('coding',), ('choupi',), ('111',), ('choupidan',), ('youku',)]

in_() 判断在xx里边

print(session.query(User.username).filter(User.username.in_(['dandan','aaa'])).all())
# 结果
[('dandan',), ('aaa',)]

notin_

print(session.query(User.username).filter(User.username.notin_(['dandan','aaa'])).all())
# 结果
[('tobee',), ('tree',), ('coding',), ('choupi',), ('111',), ('choupidan',), ('youku',)]

is_ 是xxx

两种表达方式 None

print(session.query(User.username).filter(User.username==None).all())
print(session.query(User.username).filter(User.username.is_(None)).all())

isnot

filter支持多条件查询

print(session.query(User.username).filter(User.username.isnot(None),User.password=='111').all())
# 结果
[('aaa',), ('111',)]

or_

from sqlalchemy import or_
print(session.query(User.username).filter(or_(User.username.isnot(None),User.password=='111')).all())

# 结果
[('dandan',), ('tobee',), ('tree',), ('aaa',), ('coding',), ('choupi',), ('111',), ('choupidan',), ('youku',)]

2、聚合函数(在sqlalchemy.func中)

count / group_by

from sqlalchemy import func
print(session.query(User.password,func.count(User.id)).group_by(User.password).all())

查询原生sql

SELECT user.password AS user_password, count(user.id) AS count_1 
FROM user GROUP BY user.password
[('111', 2), ('123asd', 1), ('234qwe', 1), ('333', 1), ('choupidan', 1), ('q1', 1), ('qwer', 1), ('zzz111', 1)]

having

having字句可以让我们筛选成组后的各种数据,where字句在聚合前先筛选记录,也就是说作用在group by和having字句前。
having子句在聚合后对组记录进行筛选。真实表中没有此数据,这些数据是通过一些函数生存。

print(session.query(User.password,func.count(User.id)).group_by(User.password).\
      having(func.count(User.id)>1).all())
# 结果
[('111', 2)]

sum

print(session.query(User.password,func.sum(User.id)).group_by(User.password).all())
# 结果
[(111, Decimal(18)), (‘123asd’, Decimal(1)), (‘234qwe’, Decimal(2)), (333, Decimal(16)), (‘choupidan’, Decimal(15)), (‘q1’, Decimal(12)), (‘qwer’, Decimal(5)), (‘zzz111’, Decimal(3))]

max

print(session.query(User.password,func.max(User.id)).group_by(User.password).all())

# 结果
[(111, 14), (‘123asd’, 1), (‘234qwe’, 2), (333, 16), (‘choupidan’, 15), (‘q1’, 12), (‘qwer’, 5), (‘zzz111’, 3)]

min

print(session.query(User.password,func.min(User.id)).group_by(User.password).all())

# 结果
[(111, 4), (‘123asd’, 1), (‘234qwe’, 2), (333, 16), (‘choupidan’, 15), (‘q1’, 12), (‘qwer’, 5), (‘zzz111’, 3)]

lable 别名

lable别名不能用在having中

extract 提取

提取时间元素

from sqlalchemy import extract
print(session.query(extract('minute',User.createtime).label('minute'),func.count(User.id)).group_by('minute').all())

基于分钟排序

[(16, 1), (27, 1), (29, 3), (44, 1), (52, 1), (57, 2)]

基于天数排序

print(session.query(extract('day',User.createtime).label('day'),func.count(User.id)).group_by('day').all())

[(6, 1), (7, 1), (9, 7)]

二、进阶操作

1、反向查询

一对多反向查询

  • sqlalchemy的数据库层
class TaskTemplateTable(db.Model, SessionMixin):
    """
    任务模板绑定的表单模板
    """
    __tablename__ = 'patrol_inspect_tasktemplatetable'
    # True: 显示点位信息
    # False 不显示点位信息
    id = db.Column(db.Integer(), primary_key=True, autoincrement=True)

    table_template_id = db.Column(db.Integer(), db.ForeignKey('patrol_inspect_tabletemplate.id'))

    task_template = db.relationship('TaskTemplate')

  • 查询层
table_obj = db.session.query(TaskTemplateTable).filter_by(id=1).first()
# 要先拿到查询表下的对象,再根据对象,进行关联表的反向查询
print(table_obj.tamplate_table.name)
>>> 'ups巡检记录表'

2、数据批量操作

数据库批量数据的插入:

  • 一般的操作都为,每一条数据提交一次的方式,这样相当影响性能,可以通过执行原生sql或者sqlalchemy支持的批量导入数据的方式。进行批量插入
  • 转化为sql:insert into 表名 values(...),(...)...;
1) 批量插入10000条数据:
db.session.execute(
    User.__table__.insert(),
    [{'name': `randint(1, 100)`,'age': randint(1, 100)} for i in xrange(10000)]
)
session.commit()
2)如何让执行的 SQL 语句增加前缀?

使用 query 对象的 prefix_with() 方法:

session.query(User.name).prefix_with('HIGH_PRIORITY').all()
session.execute(User.__table__.insert().prefix_with('IGNORE'), {'id': 1, 'name': '1'})
3)如何替换一个已有主键的记录?

使用 session.merge() 方法替代 session.add(),其实就是 SELECT + UPDATE:

user = User(id=1, name='ooxx')
session.merge(user)
session.commit()

或者使用 MySQL 的 INSERT … ON DUPLICATE KEY UPDATE,需要用到 @compiles 装饰器,有点难懂,自己看吧:《SQLAlchemy ON DUPLICATE KEY UPDATE》 和 sqlalchemy_mysql_ext。

4)如何使用无符号整数?

可以使用 MySQL 的方言:

from sqlalchemy.dialects.mysql import INTEGER

id = Column(INTEGER(unsigned=True), primary_key=True)
5)模型的属性名需要和表的字段名不一样怎么办?

开发时遇到过一个奇怪的需求,有个其他系统的表里包含了一个“from”字段,这在 Python 里是关键字,于是只能这样处理了:
from_ = Column('from', CHAR(10))

6)如何获取字段的长度?

Column 会生成一个很复杂的对象,想获取长度比较麻烦,这里以 User.name 为例:
User.name.property.columns[0].type.length

7)如何指定使用 InnoDB,以及使用 UTF-8 编码?

最简单的方式就是修改数据库的默认配置。如果非要在代码里指定的话,可以这样:

class User(BaseModel):
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'mysql_charset': 'utf8'
    }

数据库批量数据删除DELETE

  • 当查询结果只有一个对象时,可直接调用改对象的delete方法即可
    • dbm.AccessToken.query.filter_by(id=1).delete()
  • 但当结果不止一个时,直接这么操作,会报错。
  • 删除记录时,默认会尝试删除 session 中符合条件的对象,而这里还不支持,所以报错
1) 批量删除数据:
# 方式一:  
token_obj_list = dbm.AccessToken.query.filter(text(sql_text)).params(**sql_params).all()

for obj in token_obj_list:
    db.session.delete(obj)
db.session.commit()

# 方式二:
     # 这里不让session同步
delte_count = AccessToken.query.filter(text(sql_text)).params(**sql_params).delete(synchronize_session=False)

print(delete_count)
session.commit()

3、复制copy对象,并新建数据到db

consume_obj = dbm.ConsumeOrderHistory.query.filter_by(id=raw_index).first()


# 直接copy对象,会造成session会话冲突,这个不能直接用copy的方式来操作
# consume_record = copy.deepcopy(consume_obj)

# 通过make_transient来实现
from sqlalchemy.orm.session import make_transient

logger.info(consume_obj)  # <pay_proxy.dbmodels.ConsumeOrderHistory object at 0x7f3ff62ac350>
logger.info(type(consume_obj))   # <class 'pay_proxy.dbmodels.ConsumeOrderHistory'>

logger.info("开始处理对象 ... ")
make_transient(consume_obj)

logger.info(consume_obj)   # <pay_proxy.dbmodels.ConsumeOrderHistory object at 0x7f3ff62ac350> ,对象的地址都没变,只是去掉了session链接
logger.info(type(consume_obj))   # <class 'pay_proxy.dbmodels.ConsumeOrderHistory'>
logger.info(dir(consume_obj))  # 仍然包含源对象的所有方法

"""
- 处理前后的两个对象是完全相等的!
- 经过其处理之后的对象,不再跟session绑定,此时只需要将其主键作相应替换即可实现复制一份数据到db
"""

# 两种方式:
# consume_obj.id = None  # 1、 主键设null,主键设置了autoincrement,则会自动生成
delattr(consume_obj, 'id')  # 2、删除其主键属性,commit到数据库时会自动赋值

db.session.add(consume_obj)
db.session.commit()

# 最终会在数据库添加除了主键不同之外,其他所有字段都跟查出来的consume_obj字段相一致的一条数据。

三、其他sql知识点

1、sql语句相关

数据库字段判空:

  • 1.为null
  • 2.为字符串的空’’
    判断是否为空(包括上边两种情况):
select * from table where column is null or trim(column)=''

这样就可以排除字段内容为null、’'的。

判断某个字段不为空,可直接用!=来做判断,便可以排除掉null""的判断

select * from table where trim(column) != ''
linux安装python依赖:[root@VM-16-5-centos noon]# pip3.6 install sqlalchemy WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3.6 install --user` instead. Collecting sqlalchemy Downloading http://mirrors.tencentyun.com/pypi/packages/5e/50/f63ff7811a8d3367a2c7fae6095f08da20e64e09762e4da1bf05706aefb1/SQLAlchemy-1.4.54-cp36-cp36m-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6MB) 100% |████████████████████████████████| 1.6MB 1.8MB/s Collecting greenlet!=0.4.17; python_version >= "3" and (platform_machine == "aarch64" or (platform_machine == "ppc64le" or (platform_machine == "x86_64" or (platform_machine == "amd64" or (platform_machine == "AMD64" or (platform_machine == "win32" or platform_machine == "WIN32")))))) (from sqlalchemy) Downloading http://mirrors.tencentyun.com/pypi/packages/1e/1e/632e55a04d732c8184201238d911207682b119c35cecbb9a573a6c566731/greenlet-2.0.2.tar.gz (164kB) 100% |████████████████████████████████| 174kB 920kB/s Collecting importlib-metadata; python_version < "3.8" (from sqlalchemy) Downloading http://mirrors.tencentyun.com/pypi/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_metadata-4.8.3-py3-none-any.whl Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->sqlalchemy) Downloading http://mirrors.tencentyun.com/pypi/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0-py3-none-any.whl Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in /usr/local/lib/python3.6/site-packages (from importlib-metadata; python_version < "3.8"->sqlalchemy) Installing collected packages: greenlet, zipp, importlib-metadata, sqlalchemy Running setup.py install for greenlet ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-xwpa9djj/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5rl6bxpe-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build/lib.linux-x86_64-3.6 creating build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/__init__.py -> build/lib.linux-x86_64-3.6/greenlet creating build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/__init__.py -> build/lib.linux-x86_64-3.6/greenlet/platform creating build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_generator.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_stack_saved.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_contextvars.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_greenlet.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_cpp.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_gc.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_extension_interface.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_version.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_throw.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_greenlet_trash.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_weakref.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_tracing.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/__init__.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/leakcheck.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_generator_nested.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_leaks.py -> build/lib.linux-x86_64-3.6/greenlet/tests running egg_info writing src/greenlet.egg-info/PKG-INFO writing dependency_links to src/greenlet.egg-info/dependency_links.txt writing requirements to src/greenlet.egg-info/requires.txt writing top-level names to src/greenlet.egg-info/top_level.txt reading manifest file 'src/greenlet.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files found matching 'benchmarks/*.json' no previously-included directories found matching 'docs/_build' warning: no files found matching '*.py' under directory 'appveyor' warning: no previously-included files matching '*.pyc' found anywhere in distribution warning: no previously-included files matching '*.pyd' found anywhere in distribution warning: no previously-included files matching '*.so' found anywhere in distribution warning: no previously-included files matching '.coverage' found anywhere in distribution writing manifest file 'src/greenlet.egg-info/SOURCES.txt' copying src/greenlet/greenlet.cpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet.h -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_allocator.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_compiler_compat.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_cpython_compat.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_exceptions.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_greenlet.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_internal.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_refs.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_slp_switch.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_thread_state.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_thread_state_dict_cleanup.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_thread_support.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/slp_platformselect.h -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/platform/setup_switch_x64_masm.cmd -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_aarch64_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_alpha_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_amd64_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm32_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm32_ios.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm64_masm.asm -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm64_masm.obj -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm64_msvc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_csky_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_m68k_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_mips_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc64_aix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc64_linux.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_aix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_linux.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_macosx.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_riscv_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_s390_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_sparc_sun_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x32_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x64_masm.asm -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x64_masm.obj -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x64_msvc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x86_msvc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x86_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/tests/_test_extension.c -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/_test_extension_cpp.cpp -> build/lib.linux-x86_64-3.6/greenlet/tests running build_ext building 'greenlet._greenlet' extension creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/src creating build/temp.linux-x86_64-3.6/src/greenlet gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c src/greenlet/greenlet.cpp -o build/temp.linux-x86_64-3.6/src/greenlet/greenlet.o gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录 error: command 'gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-xwpa9djj/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5rl6bxpe-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-xwpa9djj/greenlet/ [root@VM-16-5-centos noon]# python3.6 getSalerInfo3.py Traceback (most recent call last): File "getSalerInfo3.py", line 13, in <module> from sqlalchemy import exc, create_engine, text ModuleNotFoundError: No module named 'sqlalchemy' [root@VM-16-5-centos noon]#报错
06-19
Windows PowerShell 版权所有(C) Microsoft Corporation。保留所有权利。 安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows (.venv1) PS D:\OCR\AW> pip install cmake -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting cmake Downloading https://pypi.tuna.tsinghua.edu.cn/packages/16/1a/6504170f8cfadde043ed5dabadcca8af50545094428ed74c44c1eac3903f/cmake-4.0.2-py3-none-win_amd64.whl (36.7 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 36.7/36.7 MB 21.8 MB/s eta 0:00:00 Installing collected packages: cmake Successfully installed cmake-4.0.2 [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> pip install dlib==19.24.0 -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting dlib==19.24.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e5/3b/7a8522a5c2ef6ff6252e46b0788b3d2c2280198c49d6ecf3b576b171045f/dlib-19.24.0.tar.gz (3.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 3.5 MB/s eta 0:00:00 Preparing metadata (setup.py) ... done Building wheels for collected packages: dlib Building wheel for dlib (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [60 lines of output] running bdist_wheel running build running build_py running build_ext C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\dlib_06503242b7ff453f95f8a7e1db2cf260\setup.py:129: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. if LooseVersion(cmake_version) < '3.1.0': Building extension for Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] Invoking CMake setup: 'cmake C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\dlib_06503242b7ff453f95f8a7e1db2cf260\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\d lib_06503242b7ff453f95f8a7e1db2cf260\build\lib.win-amd64-cpython-39 -DPYTHON_EXECUTABLE=D:\OCR\AW\.venv1\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\dlib_06503242b7ff453f95f8a7e1db2cf260\build\lib.win-amd64-cpython-39 -A x64' -- Building for: Visual Studio 17 2022 CMake Error at CMakeLists.txt:2 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument <min> value. Or, use the <min>...<max> syntax to tell CMake that the project requires at least <min> but has been updated to work with policies introduced by <max> or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. -- Configuring incomplete, errors occurred! Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\dlib_06503242b7ff453f95f8a7e1db2cf260\setup.py", line 222, in <module> setup( File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\__init__.py", line 103, in setup return distutils.core.setup(**attrs) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\core.py", line 185, in setup return run_commands(dist) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands dist.run_commands() File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands self.run_command(cmd) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\dist.py", line 1001, in run_command super().run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command cmd_obj.run() File "D:\OCR\AW\.venv1\lib\site-packages\wheel\bdist_wheel.py", line 364, in run self.run_command("build") File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command self.distribution.run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\dist.py", line 1001, in run_command super().run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command cmd_obj.run() File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run self.run_command(cmd_name) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command self.distribution.run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\dist.py", line 1001, in run_command super().run_command(command) File "D:\OCR\AW\.venv1\lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command cmd_obj.run() File "C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\dlib_06503242b7ff453f95f8a7e1db2cf260\setup.py", line 134, in run self.build_extension(ext) File "C:\Users\Admin\AppData\Local\Temp\pip-install-8ye8wh45\dlib_06503242b7ff453f95f8a7e1db2cf260\setup.py", line 171, in build_extension subprocess.check_call(cmake_setup, cwd=build_folder) File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 373, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-8ye8wh45\\dlib_06503242b7ff453f95f8a7e1db2cf260\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Admin\\AppD ata\\Local\\Temp\\pip-install-8ye8wh45\\dlib_06503242b7ff453f95f8a7e1db2cf260\\build\\lib.win-amd64-cpython-39', '-DPYTHON_EXECUTABLE=D:\\OCR\\AW\\.venv1\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Admin\\AppData\\Local\\Temp\\pip-install-8ye8wh45\\dlib_06503242b7ff453f95f8a7e1db2cf260\\build\\lib.win-amd64-cpython-39', '-A', 'x64']' returned non-zero exit status 1. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Running setup.py clean for dlib Failed to build dlib ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> pip install cmake -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: cmake in d:\ocr\aw\.venv1\lib\site-packages (4.0.2) [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> pip install boost -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting boost Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cd/e9/fd77f318eba4976c9ed9df341c13daebe69cace8723dbd0f3d39a0dddb08/boost-0.1.tar.gz (6.3 kB) Preparing metadata (setup.py) ... done Collecting Mastodon.py (from boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cf/d7/632b8b14a13eb33a9fcc5c3354f878fa39dfb5f51ef6283b24fce84c5796/mastodon_py-2.0.1-py3-none-any.whl (108 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 108.5/108.5 kB 701.7 kB/s eta 0:00:00 Collecting sqlalchemy (from boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b0/1f/f68c58970d80ea5a1868ca5dc965d154a3b711f9ab06376ad9840d1475b8/sqlalchemy-2.0.41-cp39-cp39-win_amd64.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 19.3 MB/s eta 0:00:00 Collecting requests>=2.4.2 (from Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7c/e4/56027c4a6b4ae70ca9de302488c5ca95ad4a39e190093d6c1a8ace08341b/requests-2.32.4-py3-none-any.whl (64 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.8/64.8 kB 3.4 MB/s eta 0:00:00 Collecting python-dateutil (from Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 kB 14.6 MB/s eta 0:00:00 Collecting python-magic-bin (from Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/07/c2/094e3d62b906d952537196603a23aec4bcd7c6126bf80eb14e6f9f4be3a2/python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl (409 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 409.3/409.3 kB 24.9 MB/s eta 0:00:00 Collecting decorator>=4.0.0 (from Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4e/8c/f3147f5c4b73e7550fe5f9352eaa956ae838d5c51eb58e7a25b9f3e2643b/decorator-5.2.1-py3-none-any.whl (9.2 kB) Collecting blurhash>=1.1.4 (from Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/80/08/163cb166a2464223a5eb8890a92cc1cf7e8c7c79a2c75e497e3d8f3a4711/blurhash-1.1.4-py2.py3-none-any.whl (5.3 kB) Collecting greenlet>=1 (from sqlalchemy->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6c/4c/bf2100cbc1bd07f39bee3b09e7eef39beffe29f5453dc2477a2693737913/greenlet-3.2.3-cp39-cp39-win_amd64.whl (296 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 296.4/296.4 kB ? eta 0:00:00 Collecting typing-extensions>=4.6.0 (from sqlalchemy->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/69/e0/552843e0d356fbb5256d21449fa957fa4eff3bbc135a74a691ee70c7c5da/typing_extensions-4.14.0-py3-none-any.whl (43 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.8/43.8 kB ? eta 0:00:00 Collecting charset_normalizer<4,>=2 (from requests>=2.4.2->Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6d/24/5849d46cf4311bbf21b424c443b09b459f5b436b1558c04e45dbb7cc478b/charset_normalizer-3.4.2-cp39-cp39-win_amd64.whl (105 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 105.8/105.8 kB ? eta 0:00:00 Collecting idna<4,>=2.5 (from requests>=2.4.2->Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl (70 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.4/70.4 kB ? eta 0:00:00 Collecting urllib3<3,>=1.21.1 (from requests>=2.4.2->Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6b/11/cc635220681e93a0183390e26485430ca2c7b5f9d33b15c74c2861cb8091/urllib3-2.4.0-py3-none-any.whl (128 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 128.7/128.7 kB ? eta 0:00:00 Collecting certifi>=2017.4.17 (from requests>=2.4.2->Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4a/7e/3db2bd1b1f9e95f7cddca6d6e75e2f2bd9f51b1246e546d88addca0106bd/certifi-2025.4.26-py3-none-any.whl (159 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 159.6/159.6 kB 10.0 MB/s eta 0:00:00 Collecting six>=1.5 (from python-dateutil->Mastodon.py->boost) Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB) Building wheels for collected packages: boost Building wheel for boost (setup.py) ... done Created wheel for boost: filename=boost-0.1-py3-none-any.whl size=12474 sha256=eba78724e39a43a1c34300def19b488974b9617617c86dc0de4abb49616e6224 Stored in directory: c:\users\admin\appdata\local\pip\cache\wheels\11\b9\d6\fd5b204a51f80a462f9767321a4f8fabf64a8bc1a1e85b1df0 Successfully built boost Installing collected packages: python-magic-bin, blurhash, urllib3, typing-extensions, six, idna, greenlet, decorator, charset_normalizer, certifi, sqlalchemy, requests, python-dateutil, Mastodon.py, boost Successfully installed Mastodon.py-2.0.1 blurhash-1.1.4 boost-0.1 certifi-2025.4.26 charset_normalizer-3.4.2 decorator-5.2.1 greenlet-3.2.3 idna-3.10 python-dateutil-2.9.0.post0 python-magic-bin-0.4.14 requests-2.32.4 six-1.17.0 sqlalchemy-2.0.41 typing-extensions-4.14.0 urllib3-2.4.0 [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW> pip install dlib -i https://pypi.tuna.tsinghua.edu.cn/simple Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting dlib Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/f4/f8949b18ec1df2ef05fc2ea1d1dd82ff2d050b8704b7d0d088017315c221/dlib-20.0.0.tar.gz (3.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 4.9 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: dlib Building wheel for dlib (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for dlib (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [48 lines of output] running bdist_wheel running build running build_ext Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\OCR\AW\.venv1\Scripts\cmake.exe\__main__.py", line 4, in <module> ModuleNotFoundError: No module named 'cmake' ================================================================================ ================================================================================ ================================================================================ CMake is not installed on your system! Or it is possible some broken copy of cmake is installed on your system. It is unfortunately very common for python package managers to include broken copies of cmake. So if the error above this refers to some file path to a cmake file inside a python or anaconda or miniconda path then you should delete that broken copy of cmake from your computer. Instead, please get an official copy of cmake from one of these known good sources of an official cmake: - cmake.org (this is how windows users should get cmake) - apt install cmake (for Ubuntu or Debian based systems) - yum install cmake (for Redhat or CenOS based systems) On a linux machine you can run `which cmake` to see what cmake you are actually using. If it tells you it's some cmake from any kind of python packager delete it and install an official cmake. More generally, cmake is not installed if when you open a terminal window and type cmake --version you get an error. So you can use that as a very basic test to see if you have cmake installed. That is, if cmake --version doesn't run from the same terminal window from which you are reading this error message, then you have not installed cmake. Windows users should take note that they need to tell the cmake installer to add cmake to their PATH. Since you can't run commands that are not in your PATH. This is how the PATH works on Linux as well, but failing to add cmake to the PATH is a particularly common problem on windows and rarely a problem on Linux. ================================================================================ ================================================================================ ================================================================================ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Failed to build dlib ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects [notice] A new release of pip is available: 23.2.1 -> 25.1.1 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv1) PS D:\OCR\AW>
06-14
PS C:\Users\Administrator\Desktop> # 检查 PowerShell 7 安装路径 PS C:\Users\Administrator\Desktop> $pwshPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" PS C:\Users\Administrator\Desktop> Test-Path $pwshPath False PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 检查版本 PS C:\Users\Administrator\Desktop> & $pwshPath -Command { $PSVersionTable } & : 无法将“C:\Program Files\PowerShell\7\pwsh.exe”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 3 + & $pwshPath -Command { $PSVersionTable } + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\Program Files\PowerShell\7\pwsh.exe:String) [], CommandNotFoundExcep tion + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> # 创建 PowerShell 7 专用配置文件 PS C:\Users\Administrator\Desktop> $pwshProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" PS C:\Users\Administrator\Desktop> if (-not (Test-Path $pwshProfile)) { >> New-Item -Path $pwshProfile -ItemType File -Force >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 添加基础配置 PS C:\Users\Administrator\Desktop> @' >> # 启用现代语法 >> Set-StrictMode -Version 3.0 >> >> # 自定义函数 >> function Invoke-Analyzer { & "E:\DesktopAnalyzer.ps1" } >> function Invoke-Verifier { & "E:\PythonEnvVerifier.ps1" } >> >> function Clean-Desktop { >> $desktopPath = [Environment]::GetFolderPath("Desktop") >> $items = @("myenv", "PythonTools", "path_diagnostic.py", "PythonEnvRepair*") >> >> $removedCount = 0 >> foreach ($item in $items) { >> $path = Join-Path $desktopPath $item >> if (Test-Path $path) { >> Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue >> $removedCount++ >> } >> } >> >> Write-Host "清理完成: 已删除 $removedCount 个项目" -ForegroundColor Green >> } >> >> # 别名设置 >> Set-Alias da Invoke-Analyzer >> Set-Alias ve Invoke-Verifier >> Set-Alias clean Clean-Desktop >> >> # 提示信息 >> Write-Host "PowerShell 7 环境已加载 (版本: $($PSVersionTable.PSVersion))" -ForegroundColor Cyan >> '@ | Set-Content -Path $pwshProfile -Encoding UTF8 PS C:\Users\Administrator\Desktop> # 创建快捷方式 PS C:\Users\Administrator\Desktop> $shortcutPath = "$env:USERPROFILE\Desktop\PowerShell 7.lnk" PS C:\Users\Administrator\Desktop> $WshShell = New-Object -ComObject WScript.Shell PS C:\Users\Administrator\Desktop> $shortcut = $WshShell.CreateShortcut($shortcutPath) PS C:\Users\Administrator\Desktop> $shortcut.TargetPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe" PS C:\Users\Administrator\Desktop> $shortcut.Arguments = "-NoExit -Command `". `'$pwshProfile`'`"" PS C:\Users\Administrator\Desktop> $shortcut.IconLocation = "$env:ProgramFiles\PowerShell\7\assets\Powershell_av_colors.ico" PS C:\Users\Administrator\Desktop> $shortcut.Save() PS C:\Users\Administrator\Desktop> # 确保分析脚本存在 PS C:\Users\Administrator\Desktop> if (-not (Test-Path "E:\DesktopAnalyzer.ps1")) { >> @' >> # 桌面分析脚本内容 >> $desktopPath = [Environment]::GetFolderPath("Desktop") >> Write-Host "`n=== 桌面文件分析报告 ===`n" -ForegroundColor Cyan >> >> $items = Get-ChildItem -Path $desktopPath -Force >> if (-not $items) { >> Write-Host "桌面是空的!" -ForegroundColor Green >> exit >> } >> >> # ... 完整脚本内容 ... >> '@ | Set-Content -Path "E:\DesktopAnalyzer.ps1" -Encoding UTF8 >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 确保验证脚本存在 PS C:\Users\Administrator\Desktop> if (-not (Test-Path "E:\PythonEnvVerifier.ps1")) { >> @' >> # 环境验证脚本内容 >> function Verify-Environment { >> # ... 完整脚本内容 ... >> } >> Verify-Environment >> '@ | Set-Content -Path "E:\EnvVerifier.ps1" -Encoding UTF8 >> } PS C:\Users\Administrator\Desktop> # 三元运算符(正确用法) PS C:\Users\Administrator\Desktop> $result = "成功" PS C:\Users\Administrator\Desktop> Write-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' : 'Red') 所在位置 行:1 字符: 63 + ... ite-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' ... + ~ 表达式或语句中包含意外的标记“?”。 所在位置 行:1 字符: 62 + Write-Host "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Gree ... + ~ 表达式中缺少右“)”。 所在位置 行:1 字符: 80 + ... "检测结果: $result" -ForegroundColor ($result -eq '成功' ? 'Green' : 'Red') + ~ 表达式或语句中包含意外的标记“)”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 空值合并运算符 PS C:\Users\Administrator\Desktop> $envVar = $null PS C:\Users\Administrator\Desktop> Write-Host "PYTHONPATH: $($envVar ?? '未设置')" 所在位置 行:1 字符: 35 + Write-Host "PYTHONPATH: $($envVar ?? '未设置')" + ~~ 表达式或语句中包含意外的标记“??”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 管道链运算符 PS C:\Users\Administrator\Desktop> Get-ChildItem *.py | ForEach-Object { "Python文件: $($_.Name)" } Python文件: test_module.py Python文件: verify_path.py PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 简化的错误处理 PS C:\Users\Administrator\Desktop> try { >> Get-Item "C:\不存在路径" -ErrorAction Stop >> } catch { >> Write-Host "错误: $_" -ForegroundColor Red >> } 错误: 找不到路径“C:\不存在路径”,因为该路径不存在。 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 类定义(PowerShell 5+) PS C:\Users\Administrator\Desktop> class FileInfo { >> [string]$Name >> [datetime]$Modified >> [double]$SizeKB >> 所在位置 行:4 字符: 5 + [double]$SizeKB + ~~~~~~~~~~~~~~~ 语句块或类型定义中缺少右“}”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndCurlyBrace PS C:\Users\Administrator\Desktop> FileInfo([System.IO.FileInfo]$file) { >> $this.Name = $file.Name >> $this.Modified = $file.LastWriteTime >> $this.SizeKB = [math]::Round($file.Length / 1KB, 2) >> } FileInfo : 无法将“FileInfo”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 5 + FileInfo([System.IO.FileInfo]$file) { + ~~~~~~~~ + CategoryInfo : ObjectNotFound: (FileInfo:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> } 所在位置 行:1 字符: 1 + } + ~ 表达式或语句中包含意外的标记“}”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 使用类 PS C:\Users\Administrator\Desktop> $files = Get-ChildItem | Where-Object { -not $_.PSIsContainer } | ForEach-Object { >> [FileInfo]::new($_) >> } 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound 找不到类型 [FileInfo]。 所在位置 行:2 字符: 5 + [FileInfo]::new($_) + ~~~~~~~~~~ + CategoryInfo : InvalidOperation: (FileInfo:TypeName) [],RuntimeException + FullyQualifiedErrorId : TypeNotFound PS C:\Users\Administrator\Desktop> $files | Format-Table Name, Modified, SizeKB PS C:\Users\Administrator\Desktop> # 创建Python虚拟环境 PS C:\Users\Administrator\Desktop> python -m venv "E:\PythonTools\clean_env" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 激活虚拟环境 PS C:\Users\Administrator\Desktop> . "E:\PythonTools\clean_env\Scripts\Activate.ps1" (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 检查Python路径 (clean_env) PS C:\Users\Administrator\Desktop> Write-Host "当前Python: $(which python)" which : 无法将“which”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 25 + Write-Host "当前Python: $(which python)" + ~~~~~ + CategoryInfo : ObjectNotFound: (which:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException 当前Python: (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 在虚拟环境中运行脚本 (clean_env) PS C:\Users\Administrator\Desktop> python -c "import sys; print(sys.path)" ['', 'C:\\Users\\Administrator\\Desktop', 'E:\\Python310\\python310.zip', 'E:\\Python310\\DLLs', 'E:\\Python310\\lib', 'E:\\Python310', 'E:\\PythonTools\\clean_env', 'E:\\PythonTools\\clean_env\\lib\\site-packages'] (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 安装依赖 (clean_env) PS C:\Users\Administrator\Desktop> pip install -r "E:\requirements.txt" Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting flask>=2.0.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ec/f9/7f9263c5695f4bd0023734af91bedb2ff8209e8de6ead162f35d8dc762fd/flask-3.1.2-py3-none-any.whl (103 kB) Collecting python-dotenv Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5f/ed/539768cf28c661b5b068d66d96a2f155c4971a5d55684a514c1a0e0dec2f/python_dotenv-1.1.1-py3-none-any.whl (20 kB) Collecting psutil Using cached https://pypi.tuna.tsinghua.edu.cn/packages/50/1b/6921afe68c74868b4c9fa424dad3be35b095e16687989ebbb50ce4fceb7c/psutil-7.0.0-cp37-abi3-win_amd64.whl (244 kB) Collecting sqlalchemy Downloading https://pypi.tuna.tsinghua.edu.cn/packages/38/2d/bfc6b6143adef553a08295490ddc52607ee435b9c751c714620c1b3dd44d/sqlalchemy-2.0.43-cp310-cp310-win_amd64.whl (2.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 68.2 MB/s eta 0:00:00 Collecting requests Using cached https://pypi.tuna.tsinghua.edu.cn/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl (64 kB) Collecting flask-sse Downloading https://pypi.tuna.tsinghua.edu.cn/packages/71/83/f9fe86f554a153fdd300fb8027121d508a2177605bd158d967ddd7325948/Flask_SSE-1.0.0-py2.py3-none-any.whl (5.0 kB) Collecting itsdangerous>=2.2.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl (16 kB) Collecting blinker>=1.9.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/10/cb/f2ad4230dc2eb1a74edf38f1a38b9b52277f75bef262d8908e60d957e13c/blinker-1.9.0-py3-none-any.whl (8.5 kB) Collecting markupsafe>=2.1.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/44/06/e7175d06dd6e9172d4a69a72592cb3f7a996a9c396eee29082826449bbc3/MarkupSafe-3.0.2-cp310-cp310-win_amd64.whl (15 kB) Collecting werkzeug>=3.1.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/52/24/ab44c871b0f07f491e5d2ad12c9bd7358e527510618cb1b803a88e986db1/werkzeug-3.1.3-py3-none-any.whl (224 kB) Collecting jinja2>=3.1.2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl (134 kB) Collecting click>=8.1.3 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/85/32/10bb5764d90a8eee674e9dc6f4db6a0ab47c8c4d0d83c27f7c39ac415a4d/click-8.2.1-py3-none-any.whl (102 kB) Collecting typing-extensions>=4.6.0 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b5/00/d631e67a838026495268c2f6884f3711a15a9a2a96cd244fdaea53b823fb/typing_extensions-4.14.1-py3-none-any.whl (43 kB) Collecting greenlet>=1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d6/6f/b60b0291d9623c496638c582297ead61f43c4b72eef5e9c926ef4565ec13/greenlet-3.2.4-cp310-cp310-win_amd64.whl (298 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 298.7/298.7 kB ? eta 0:00:00 Collecting certifi>=2017.4.17 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl (161 kB) Collecting charset_normalizer<4,>=2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e2/c6/f05db471f81af1fa01839d44ae2a8bfeec8d2a8b4590f16c4e7393afd323/charset_normalizer-3.4.3-cp310-cp310-win_amd64.whl (107 kB) Collecting urllib3<3,>=1.21.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl (129 kB) Collecting idna<4,>=2.5 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl (70 kB) Collecting six Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB) Collecting redis Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e8/02/89e2ed7e85db6c93dfa9e8f691c5087df4e3551ab39081a4d7c6d1f90e05/redis-6.4.0-py3-none-any.whl (279 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 279.8/279.8 kB ? eta 0:00:00 Collecting colorama Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB) Collecting async-timeout>=4.0.3 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fe/ba/e2081de779ca30d473f21f5b30e0e737c438205440784c7dfc81efc2b029/async_timeout-5.0.1-py3-none-any.whl (6.2 kB) Installing collected packages: urllib3, typing-extensions, six, python-dotenv, psutil, markupsafe, itsdangerous, idna, greenlet, colorama, charset_normalizer, certifi, blinker, async-timeout, werkzeug, sqlalchemy, requests, redis, jinja2, click, flask, flask-sse Successfully installed async-timeout-5.0.1 blinker-1.9.0 certifi-2025.8.3 charset_normalizer-3.4.3 click-8.2.1 colorama-0.4.6 flask-3.1.2 flask-sse-1.0.0 greenlet-3.2.4 idna-3.10 itsdangerous-2.2.0 jinja2-3.1.6 markupsafe-3.0.2 psutil-7.0.0 python-dotenv-1.1.1 redis-6.4.0 requests-2.32.5 six-1.17.0 sqlalchemy-2.0.43 typing-extensions-4.14.1 urllib3-2.5.0 werkzeug-3.1.3 [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 运行Python脚本 (clean_env) PS C:\Users\Administrator\Desktop> python "E:\verify_path.py" E:\Python310\python.exe: can't open file 'E:\\verify_path.py': [Errno 2] No such file or directory (clean_env) PS C:\Users\Administrator\Desktop> (clean_env) PS C:\Users\Administrator\Desktop> # 停用虚拟环境 (clean_env) PS C:\Users\Administrator\Desktop> deactivate PS C:\Users\Administrator\Desktop> # 保存为 E:\Setup-PowerShell7.ps1 PS C:\Users\Administrator\Desktop> param( >> [switch]$Install, >> [switch]$Configure >> ) PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 安装 PowerShell 7 PS C:\Users\Administrator\Desktop> if ($Install) { >> $url = "https://github.com/PowerShell/PowerShell/releases/download/v7.3.6/PowerShell-7.3.6-win-x64.msi" >> $output = "$env:TEMP\PowerShell-7.3.6-win-x64.msi" >> >> Invoke-WebRequest -Uri $url -OutFile $output >> Start-Process msiexec.exe -ArgumentList "/i `"$output`" /qn" -Wait >> Remove-Item $output -Force >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 配置环境 PS C:\Users\Administrator\Desktop> if ($Configure) { >> # 创建配置文件 >> $pwshProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" >> @' >> # 配置文件内容 >> '@ | Set-Content -Path $pwshProfile -Encoding UTF8 >> >> # 创建脚本文件 >> # ... >> >> # 创建快捷方式 >> # ... >> >> Write-Host "PowerShell 7 环境配置完成!" -ForegroundColor Green >> Write-Host "请使用桌面上的 'PowerShell 7' 快捷方式启动" -ForegroundColor Yellow >> } PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 使用示例: PS C:\Users\Administrator\Desktop> # .\Setup-PowerShell7.ps1 -Install -Configure PS C:\Users\Administrator\Desktop> .\Setup-PowerShell7.ps1 -Install -Configure .\Setup-PowerShell7.ps1 : 无法将“.\Setup-PowerShell7.ps1”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + .\Setup-PowerShell7.ps1 -Install -Configure + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (.\Setup-PowerShell7.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> da # 运行桌面分析 da : 无法将“da”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + da # 运行桌面分析 + ~~ + CategoryInfo : ObjectNotFound: (da:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> ve # 运行环境验证 ve : 无法将“ve”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + ve # 运行环境验证 + ~~ + CategoryInfo : ObjectNotFound: (ve:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> clean # 清理桌面 clean : 无法将“clean”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1 + clean # 清理桌面 + ~~~~~ + CategoryInfo : ObjectNotFound: (clean:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\Administrator\Desktop> # 创建并激活环境 PS C:\Users\Administrator\Desktop> python -m venv "E:\myenv" PS C:\Users\Administrator\Desktop> . "E:\myenv\Scripts\Activate.ps1" (myenv) PS C:\Users\Administrator\Desktop> (myenv) PS C:\Users\Administrator\Desktop> # 在虚拟环境中工作 (myenv) PS C:\Users\Administrator\Desktop> pip install pandas Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting pandas Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/df/5ab92fcd76455a632b3db34a746e1074d432c0cdbbd28d7cd1daba46a75d/pandas-2.3.2-cp310-cp310-win_amd64.whl (11.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.3/11.3 MB 81.8 MB/s eta 0:00:00 Collecting numpy>=1.22.4 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a3/dd/4b822569d6b96c39d1215dbae0582fd99954dcbcf0c1a13c61783feaca3f/numpy-2.2.6-cp310-cp310-win_amd64.whl (12.9 MB) Collecting pytz>=2020.1 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/81/c4/34e93fe5f5429d7570ec1fa436f1986fb1f00c3e0f43a589fe2bbcd22c3f/pytz-2025.2-py2.py3-none-any.whl (509 kB) Collecting tzdata>=2022.7 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl (347 kB) Collecting python-dateutil>=2.8.2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB) Collecting six>=1.5 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl (11 kB) Installing collected packages: pytz, tzdata, six, numpy, python-dateutil, pandas Successfully installed numpy-2.2.6 pandas-2.3.2 python-dateutil-2.9.0.post0 pytz-2025.2 six-1.17.0 tzdata-2025.2 [notice] A new release of pip available: 22.3.1 -> 25.2 [notice] To update, run: python.exe -m pip install --upgrade pip (myenv) PS C:\Users\Administrator\Desktop> python myscript.py E:\Python310\python.exe: can't open file 'C:\\Users\\Administrator\\Desktop\\myscript.py': [Errno 2] No such file or directory (myenv) PS C:\Users\Administrator\Desktop> (myenv) PS C:\Users\Administrator\Desktop> # 退出环境 (myenv) PS C:\Users\Administrator\Desktop> deactivate PS C:\Users\Administrator\Desktop> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser PS C:\Users\Administrator\Desktop> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser PS C:\Users\Administrator\Desktop> $scriptPath = Join-Path $PSScriptRoot "myscript.ps1" Join-Path : 无法将参数绑定到参数“Path”,因为该参数为空字符串。 所在位置 行:1 字符: 25 + $scriptPath = Join-Path $PSScriptRoot "myscript.ps1" + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Join-Path],ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Join PathCommand PS C:\Users\Administrator\Desktop>
最新发布
08-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值