mac python虚拟环境报错
来源:10-14 group分组

爽哥V武
2019-05-13
在mac环境中,尝试在虚拟环境中写了个程序,最开始还能用,但是重新打开时报如下错误:
Traceback (most recent call last):
File “/Users/zhangshuang/Documents/background/python/venv/flask_venv/bin/pip”, line 7, in
from pip._internal import main
File “/Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/site-packages/pip/_internal/init.py”, line 40, in
from pip._internal.cli.autocompletion import autocomplete
File “/Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/site-packages/pip/_internal/cli/autocompletion.py”, line 8, in
from pip._internal.cli.main_parser import create_main_parser
File “/Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/site-packages/pip/_internal/cli/main_parser.py”, line 8, in
from pip._internal.cli import cmdoptions
File “/Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/site-packages/pip/_internal/cli/cmdoptions.py”, line 19, in
from pip._internal.locations import USER_CACHE_DIR, src_prefix
File “/Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/site-packages/pip/_internal/locations.py”, line 6, in
import platform
File “/Users/zhangshuang/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/platform.py”, line 116, in
import sys, os, re, subprocess
File “/Users/zhangshuang/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/subprocess.py”, line 136, in
import _posixsubprocess
ImportError: dlopen(/Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/lib-dynload/_posixsubprocess.cpython-36m-darwin.so, 2): Symbol not found: __Py_set_inheritable_async_safe
Referenced from: /Users/zhangshuang/Documents/background/python/venv/flask_venv/lib/python3.6/lib-dynload/_posixsubprocess.cpython-36m-darwin.so
Expected in: flat namespace
2回答
-
爽哥V武
提问者
2019-05-14
该代码实现word转html的功能: 最开始在pycharm中能用,但是我关了一次pycharm,再打开就不能用了,不在虚拟环境中该代码还是可以使用的。 from flask import Flask, request import os, re, base64, time, random from pydocx import PyDocX from flask_cors import CORS from qiniu import Auth, put_file, etag import qiniu.config # #七牛云的账号设置 access_key = '' secret_key = '' bucket_name = '' #要上传的空间 base_url = '' # # #构建鉴权对象 q = Auth(access_key, secret_key) app = Flask(__name__) CORS(app) upload_file_folder = os.path.join(os.getcwd(),'upload') @app.route('/w/') def hello_world(): return 'Hello World!' # 上传操作 @app.route('/w/upload', methods=['GET', 'POST']) def upload(): file = request.files['file'] if not file: return 'null' if check_file_type(file.filename): # 判断upload_file_folder目录是否存在,如果不存在,创建目录 if not os.path.exists(upload_file_folder): os.mkdir(upload_file_folder) wordFileName = str(time.time()) + str(random.randint(1, 1000)) + '.docx' file.save(os.path.join(upload_file_folder, wordFileName)) html = PyDocX.to_html(os.path.join(upload_file_folder, wordFileName)) # 正则处理内容 html = re.findall('<body>(.*)</body>', html)[0] # 正则处理内容,将base64的字符串保存图片,并上传至七牛云,然后替换html代码 reg = '<img.*?src="(.*?)".*?>' imgList = re.findall(reg, html) for x in imgList: img = base64.b64decode(','.join(x.split(',')[1:])) # 去除'data:image/jpeg;base64,' imgName = str(int(time.time())) + str(random.randint(1, 1000)) + '.jpg' imgPath = os.path.join(upload_file_folder, imgName) imgFile = open(imgPath, 'wb') imgFile.write(img) imgFile.close() # 上传后保存的文件名 key = imgName # 生成上传Token,可以指定过期时间等 token = q.upload_token(bucket_name, key, 3600) ret, info = put_file(token, key, imgPath) assert ret['key'] == key assert ret['hash'] == etag(imgPath) if (os.path.exists(imgPath)): os.remove(imgPath) html = html.replace(x, base_url + ret['key']) # 替换图片地址 if (os.path.exists(os.path.join(upload_file_folder, wordFileName))): os.remove(os.path.join(upload_file_folder, wordFileName)) return html else: return 'no' # 检查文件类型 def check_file_type(filename): file_type = ['doc', 'docx'] # 获取文件后缀 ext = filename.split('.')[1] # 判断文件是否是允许上传得类型 if ext in file_type: return True else: return False if __name__ == '__main__': app.run()
012019-05-14 -
7七月
2019-05-13
这个。。。是什么。你得具体描述下你的问题,代码。
00
相似问题