ModuleNotFoundError: No module named ‘astunparse‘

当遇到'astunparse'模块未找到的错误时,博主分享了关闭编辑器、避免使用不推荐的pip安装方法。问题最终定位为TensorFlow1.13.1版本的包问题。通过卸载并重新安装该版本的TensorFlow,成功解决了问题。提醒读者,正确的重启和安装通常能解决大部分问题。
部署运行你感兴趣的模型镜像

之前正常运行的代码报错:ModuleNotFoundError: No module named 'astunparse',解决方法:

首先,关掉pycharm、vscode等编辑软件

第二,别慌,百度什么pip不要信

我pip以后报错 no attribute placeholder,后来无限循环报错。最终,我看到可能是tensorflow有问题,我用的是tensorflow==1.13.1版本,可能是软件包有问题,采用了卸载、重下,具体常规代码如下:

pip uninstall tensorflow==1.13.1  #卸载成功

pip install tensorflow==1.13.1 #OK,成果解决 

万能的重启、万能的安装。

最后,大家科研顺利~

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.9

TensorFlow-v2.9

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

Microsoft Windows [版本 10.0.19043.928] (c) Microsoft Corporation。保留所有权利。 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2>C:\Users\Administrator\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/Ad ministrator/PycharmProjects/pythonProject2/main.py Traceback (most recent call last): File "C:/Users/Administrator/PycharmProjects/pythonProject2/main.py", line 2, in <module> from tensorflow.keras.layers import Input, Dense, Reshape, Flatten, Dropout, multiply ModuleNotFoundError: No module named 'tensorflow' (venv) C:\Users\Administrator\PycharmProjects\pythonProject2>Traceback (most recent call last): 'Traceback' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2> File "C:/Users/Administrator/PycharmProjects/pythonProject2/main.py", line 2, in <modul e> 命令语法不正确。 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2> from tensorflow.keras.layers import Input, Dense, Reshape, Flatten, Dropout, multiply 'from' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2>ModuleNotFoundError: No module named 'tensorflow' 'ModuleNotFoundError:' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2> (venv) C:\Users\Administrator\PycharmProjects\pythonProject2>Process finished with exit code 1 'Process' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2>pip install tensorflow Collecting tensorflow Downloading tensorflow-2.13.1-cp38-cp38-win_amd64.whl.metadata (2.6 kB) INFO: pip is looking at multiple versions of tensorflow to determine which version is compatible with other requirements. This could take a while. Downloading tensorflow-2.13.0-cp38-cp38-win_amd64.whl.metadata (2.6 kB) Collecting tensorflow-intel==2.13.0 (from tensorflow) Downloading tensorflow_intel-2.13.0-cp38-cp38-win_amd64.whl.metadata (4.1 kB) Collecting absl-py>=1.0.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading absl_py-2.2.2-py3-none-any.whl.metadata (2.6 kB) Collecting astunparse>=1.6.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading astunparse-1.6.3-py2.py3-none-any.whl.metadata (4.4 kB) Collecting flatbuffers>=23.1.21 (from tensorflow-intel==2.13.0->tensorflow) Downloading flatbuffers-25.2.10-py2.py3-none-any.whl.metadata (875 bytes) Collecting gast<=0.4.0,>=0.2.1 (from tensorflow-intel==2.13.0->tensorflow) Downloading gast-0.4.0-py3-none-any.whl.metadata (1.1 kB) Collecting google-pasta>=0.1.1 (from tensorflow-intel==2.13.0->tensorflow) Downloading google_pasta-0.2.0-py3-none-any.whl.metadata (814 bytes) Collecting h5py>=2.9.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading h5py-3.11.0-cp38-cp38-win_amd64.whl.metadata (2.5 kB) Collecting libclang>=13.0.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading libclang-18.1.1-py2.py3-none-win_amd64.whl.metadata (5.3 kB) Collecting numpy<=1.24.3,>=1.22 (from tensorflow-intel==2.13.0->tensorflow) Downloading numpy-1.24.3-cp38-cp38-win_amd64.whl.metadata (5.6 kB) Collecting opt-einsum>=2.3.2 (from tensorflow-intel==2.13.0->tensorflow) Downloading opt_einsum-3.4.0-py3-none-any.whl.metadata (6.3 kB) Collecting packaging (from tensorflow-intel==2.13.0->tensorflow) Downloading packaging-25.0-py3-none-any.whl.metadata (3.3 kB) Collecting protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 (from tensorflow-intel==2.13.0->tensorflow) Downloading protobuf-4.25.7-cp38-cp38-win_amd64.whl.metadata (541 bytes) Requirement already satisfied: setuptools in c:\users\administrator\pycharmprojects\pythonproject2\venv\lib\site-packages (from tensorflow-intel==2.13 .0->tensorflow) (75.3.0) Collecting six>=1.12.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB) Collecting termcolor>=1.1.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading termcolor-2.4.0-py3-none-any.whl.metadata (6.1 kB) Collecting typing-extensions<4.6.0,>=3.6.6 (from tensorflow-intel==2.13.0->tensorflow) Downloading typing_extensions-4.5.0-py3-none-any.whl.metadata (8.5 kB) Collecting wrapt>=1.11.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading wrapt-1.17.2-cp38-cp38-win_amd64.whl.metadata (6.5 kB) Collecting grpcio<2.0,>=1.24.3 (from tensorflow-intel==2.13.0->tensorflow) Downloading grpcio-1.70.0-cp38-cp38-win_amd64.whl.metadata (4.0 kB) Collecting tensorboard<2.14,>=2.13 (from tensorflow-intel==2.13.0->tensorflow) Downloading tensorboard-2.13.0-py3-none-any.whl.metadata (1.8 kB) Collecting tensorflow-estimator<2.14,>=2.13.0 (from tensorflow-intel==2.13.0->tensorflow) Downloading tensorflow_estimator-2.13.0-py2.py3-none-any.whl.metadata (1.3 kB) Collecting keras<2.14,>=2.13.1 (from tensorflow-intel==2.13.0->tensorflow) Downloading keras-2.13.1-py3-none-any.whl.metadata (2.4 kB) Collecting tensorflow-io-gcs-filesystem>=0.23.1 (from tensorflow-intel==2.13.0->tensorflow) Downloading tensorflow_io_gcs_filesystem-0.31.0-cp38-cp38-win_amd64.whl.metadata (14 kB) Collecting wheel<1.0,>=0.23.0 (from astunparse>=1.6.0->tensorflow-intel==2.13.0->tensorflow) Downloading wheel-0.45.1-py3-none-any.whl.metadata (2.3 kB) INFO: pip is looking at multiple versions of tensorboard to determine which version is compatible with other requirements. This could take a while. ERROR: Ignored the following versions that require a different python version: 0.46.0 Requires-Python >=3.9; 0.46.1 Requires-Python >=3.9; 1.25.0 Requ ires-Python >=3.9; 1.25.1 Requires-Python >=3.9; 1.25.2 Requires-Python >=3.9; 1.26.0 Requires-Python <3.13,>=3.9; 1.26.1 Requires-Python <3.13,>=3.9; 1.26.2 Requires-Python >=3.9; 1.26.3 Requires-Python >=3.9; 1.26.4 Requires-Python >=3.9; 1.71.0 Requires-Python >=3.9; 1.71.0rc2 Requires-Python >=3 .9; 1.72.0 Requires-Python >=3.9; 1.72.0rc1 Requires-Python >=3.9; 2.0.0 Requires-Python >=3.9; 2.0.1 Requires-Python >=3.9; 2.0.2 Requires-Python >=3 .9; 2.1.0 Requires-Python >=3.10; 2.1.0rc1 Requires-Python >=3.10; 2.1.1 Requires-Python >=3.10; 2.1.2 Requires-Python >=3.10; 2.1.3 Requires-Python > =3.10; 2.14.0 Requires-Python >=3.9; 2.14.0rc0 Requires-Python >=3.9; 2.14.1 Requires-Python >=3.9; 2.15.0 Requires-Python >=3.9; 2.15.1 Requires-Pyth on >=3.9; 2.15.2 Requires-Python >=3.9; 2.16.0 Requires-Python >=3.9; 2.16.1 Requires-Python >=3.9; 2.16.2 Requires-Python >=3.9; 2.17.0 Requires-Pyth on >=3.9; 2.17.1 Requires-Python >=3.9; 2.18.0 Requires-Python >=3.9; 2.19.0 Requires-Python >=3.9; 2.2.0 Requires-Python >=3.10; 2.2.0rc1 Requires-Py thon >=3.10; 2.2.1 Requires-Python >=3.10; 2.2.2 Requires-Python >=3.10; 2.2.3 Requires-Python >=3.10; 2.2.4 Requires-Python >=3.10; 2.2.5 Requires-Py thon >=3.10; 2.2.6 Requires-Python >=3.10; 2.5.0 Requires-Python >=3.9; 3.0.0 Requires-Python >=3.9; 3.0.1 Requires-Python >=3.9; 3.0.2 Requires-Pytho n >=3.9; 3.0.3 Requires-Python >=3.9; 3.0.4 Requires-Python >=3.9; 3.0.5 Requires-Python >=3.9; 3.1.0 Requires-Python >=3.9; 3.1.1 Requires-Python >=3 .9; 3.10.0 Requires-Python >=3.9; 3.12.0 Requires-Python >=3.9; 3.12.1 Requires-Python >=3.9; 3.13.0 Requires-Python >=3.9; 3.2.0 Requires-Python >=3. 9; 3.2.1 Requires-Python >=3.9; 3.3.0 Requires-Python >=3.9; 3.3.1 Requires-Python >=3.9; 3.3.2 Requires-Python >=3.9; 3.3.3 Requires-Python >=3.9; 3. 4.0 Requires-Python >=3.9; 3.4.1 Requires-Python >=3.9; 3.5.0 Requires-Python >=3.9; 3.6.0 Requires-Python >=3.9; 3.7.0 Requires-Python >=3.9; 3.8.0 R equires-Python >=3.9; 3.9.0 Requires-Python >=3.9; 3.9.1 Requires-Python >=3.9; 3.9.2 Requires-Python >=3.9; 6.30.0 Requires-Python >=3.9; 6.30.0rc1 R equires-Python >=3.9; 6.30.0rc2 Requires-Python >=3.9; 6.30.1 Requires-Python >=3.9; 6.30.2 Requires-Python >=3.9; 6.31.0 Requires-Python >=3.9; 6.31. 0rc1 Requires-Python >=3.9; 6.31.0rc2 Requires-Python >=3.9 ERROR: Could not find a version that satisfies the requirement google-auth<3,>=1.6.3 (from tensorboard) (from versions: none) [notice] A new release of pip is available: 24.3.1 -> 25.0.1 [notice] To update, run: python.exe -m pip install --upgrade pip ERROR: No matching distribution found for google-auth<3,>=1.6.3 (venv) C:\Users\Administrator\PycharmProjects\pythonProject2>^A^A
05-24
import random import string import ast import astor import base64 import zlib from cryptography.fernet import Fernet class CodeObfuscator: def __init__(self): self.var_mapping = {} self.func_mapping = {} self.class_mapping = {} self.string_mapping = {} self.key = Fernet.generate_key() self.cipher = Fernet(self.key) def random_name(self, length=12): """生成随机标识符名""" return ''.join(random.choices(string.ascii_letters, k=length)) def encrypt_string(self, s): """加密字符串并返回Base64编码""" encrypted = self.cipher.encrypt(s.encode()) return base64.b64encode(encrypted).decode() def generate_dummy_code(self): """生成无意义的代码片段""" dummies = [ "for _ in range(random.randint(1, 10)): pass", "if False: print('Never executed')", "[x for x in range(100) if x % 2 == 0]", "__import__('os').system('echo harmless')" ] return ast.parse(random.choice(dummies)).body def visit_Assign(self, node): """处理赋值语句""" # 重命名左侧变量 for target in node.targets: if isinstance(target, ast.Name): if target.id not in self.var_mapping: self.var_mapping[target.id] = self.random_name() target.id = self.var_mapping[target.id] return node def visit_FunctionDef(self, node): """处理函数定义""" # 重命名函数 if node.name not in self.func_mapping: self.func_mapping[node.name] = self.random_name() node.name = self.func_mapping[node.name] # 重命名参数 for arg in node.args.args: if arg.arg not in self.var_mapping: self.var_mapping[arg.arg] = self.random_name() arg.arg = self.var_mapping[arg.arg] # 添加虚假代码 if random.random() > 0.3: # 70%概率添加虚假代码 node.body = self.generate_dummy_code() + node.body return node def visit_ClassDef(self, node): """处理类定义""" # 重命名类 if node.name not in self.class_mapping: self.class_mapping[node.name] = self.random_name() node.name = self.class_mapping[node.name] # 重命名类方法 for item in node.body: if isinstance(item, ast.FunctionDef): self.visit(item) return node def visit_Str(self, node): """处理字符串""" # 加密字符串并替换 if node.s not in self.string_mapping: self.string_mapping[node.s] = self.encrypt_string(node.s) encrypted_str = ast.Call( func=ast.Attribute( value=ast.Call( func=ast.Name(id='Fernet', ctx=ast.Load()), args=[ast.Str(s=self.key.decode())], keywords=[] ), attr='decrypt', ctx=ast.Load() ), args=[ast.Call( func=ast.Name(id='base64.b64decode', ctx=ast.Load()), args=[ast.Str(s=self.string_mapping[node.s])], keywords=[] )], keywords=[] ) return ast.Call( func=ast.Attribute(value=encrypted_str, attr='decode', ctx=ast.Load()), args=[], keywords=[] ) def flatten_control_flow(self, node): """扁平化控制流""" if isinstance(node, (ast.If, ast.For, ast.While)): # 添加冗余条件 dummy_condition = ast.Compare( left=ast.Constant(value=random.randint(1, 100)), ops=[ast.Eq()], comparators=[ast.Constant(value=random.randint(1, 100))] ) new_condition = ast.BoolOp( op=ast.Or(), values=[node.test, dummy_condition] ) node.test = new_condition return node def obfuscate(self, source_code): """主混淆函数""" # 解析AST tree = ast.parse(source_code) # 遍历AST并应用混淆 transformer = ast.NodeTransformer() transformer.visit_Assign = self.visit_Assign transformer.visit_FunctionDef = self.visit_FunctionDef transformer.visit_ClassDef = self.visit_ClassDef transformer.visit_Str = self.visit_Str transformer.visit = self.flatten_control_flow obfuscated_tree = transformer.visit(tree) # 添加导入语句 import_nodes = ast.parse("import base64\nfrom cryptography.fernet import Fernet") obfuscated_tree.body = import_nodes.body + obfuscated_tree.body # 生成混淆后的代码 return astor.to_source(obfuscated_tree) def compress_code(self, code): """压缩代码并添加解压执行层""" compressed = zlib.compress(code.encode()) b64_compressed = base64.b64encode(compressed).decode() wrapper = f""" import base64, zlib exec(zlib.decompress(base64.b64decode('{b64_compressed}')).decode()) """ return wrapper if __name__ == "__main__": # 使用示例 input_file = "deepseek_python_20250820_88b63b.py" output_file = "obfuscated_deepseek.py" with open(input_file, "r", encoding="utf-8") as f: source_code = f.read() obfuscator = CodeObfuscator() obfuscated_code = obfuscator.obfuscate(source_code) compressed_code = obfuscator.compress_code(obfuscated_code) with open(output_file, "w", encoding="utf-8") as f: f.write(compressed_code) print(f"Obfuscation complete! Output saved to {output_file}") print(f"Encryption key: {obfuscator.key.decode()} (Keep this secret!)") 发生异常:ModuleNotFoundError× No module named 'astor' File“C:\Users\卓越生活\Desktop\py加密及代码混淆设置工具.py”,line 4,in <modulex import astor ModuleNotFoundError: No module named 'astor'
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值