{"id":980,"date":"2023-06-06T18:09:40","date_gmt":"2023-06-06T10:09:40","guid":{"rendered":"http:\/\/xinyixx.com\/?p=980"},"modified":"2023-06-07T00:01:11","modified_gmt":"2023-06-06T16:01:11","slug":"python8","status":"publish","type":"post","link":"https:\/\/www.xinyixx.com\/index.php\/2023\/06\/06\/python8\/","title":{"rendered":"python\u7a0b\u5e8f8\uff1a\u5199\u4e00\u4e2a\u5b57\u7b26\u753b\u751f\u6210\u7a0b\u5e8f2.0"},"content":{"rendered":"<p>\u6253\u7b97\u5199\u4e00\u4e2a\u6709\u7f8e\u89c2GUI\u754c\u9762\u7684\u5b57\u7b26\u753b\u7a0b\u5e8f\uff0c\u76ee\u524dbug\u8fd8\u6ca1\u89e3\u51b3\uff0c\u6682\u65f6\u5728\u8fd9\u52a0\u4e2a\u4e66\u7b7e\u3002\u7531\u4e8e\u5199\u8fd9\u4e2a\u7a0b\u5e8f\u9700\u8981\u7684\u6a21\u5757\u6bd4\u8f83\u591a\uff0c\u901a\u8fc7<code>pip freeze &gt; requirements.txt<\/code>   \u5df2\u5c06\u6240\u6709\u6a21\u5757\u53ca\u7248\u672c\u8f93\u51fa\u5230txt\u6587\u672c\u4e2d<\/p>\n\n\n\n<p>\u901a\u8fc7\u547d\u4ee4\uff1a<code>pip install -r requirements.txt<\/code><\/p>\n\n\n\n<p>\u6279\u91cf\u5bfc\u5165\u6240\u7528\u5230\u7684\u6a21\u5757\u53ca\u7248\u672c\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u7a0b\u5e8f\u6e90\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>import streamlit as st\nfrom PIL import Image\nimport requests\nfrom io import BytesIO\nimport pyfiglet\n# \u8bbe\u7f6e\u9875\u9762\u6807\u9898\nst.set_page_config(page_title=\"\u56fe\u7247\u8f6c\u5b57\u7b26\u753b\", page_icon=\":art:\", layout=\"wide\")\n\n# \u8bbe\u7f6e\u9875\u9762\u5e03\u5c40\ncol1, col2 = st.beta_columns([1, 3])\nwith col1:\n    st.write(\"\")\nwith col2:\n    st.title(\"\u56fe\u7247\u8f6c\u5b57\u7b26\u753b\")\n# \u4e0a\u4f20\u56fe\u7247\nuploaded_file = st.file_uploader(\"\u4e0a\u4f20\u56fe\u7247\", type=[\"jpg\", \"jpeg\", \"png\"])\n# \u56fe\u7247\u8f6c\u5b57\u7b26\u753b\nif uploaded_file is not None:\n    # \u663e\u793a\u539f\u59cb\u56fe\u50cf\n    st.subheader(\"\u539f\u59cb\u56fe\u50cf\")\n    image = Image.open(uploaded_file)\n    st.image(image, caption=\"\u539f\u59cb\u56fe\u50cf\", use_column_width=True)\n    # \u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u5b57\u7b26\u753b\n    st.subheader(\"\u5b57\u7b26\u753b\")\n    img_width, img_height = image.size\n    aspect_ratio = img_height \/ img_width\n    new_width = 100\n    new_height = int(aspect_ratio * new_width * 0.55)\n    image = image.resize((new_width, new_height))\n    image = image.convert('L')\n    pixels = image.getdata()\n    chars = \"\".join([pyfiglet.figlet_format(pixel_to_char(pixel), font='big') for pixel in pixels])\n    st.write(chars)\n\n# \u50cf\u7d20\u8f6c\u5b57\u7b26\ndef pixel_to_char(pixel):\n    char_list = [' ', '.', '*', ':', 'o', '&amp;', '8', '#', '@']\n    num_chars = len(char_list)\n    gray = int(0.2126 * pixel[0] + 0.7152 * pixel[1] + 0.0722 * pixel[2])\n    return char_list[int(gray \/ (255 \/ num_chars))]\n<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u7528\u5230\u4e86streamlit \uff0c\u9700\u8981\u5728\u7ec8\u7aef\u754c\u9762\u8f93\u5165\u547d\u4ee4\uff1a<\/p>\n\n\n\n<p><code>streamlit run C:\\Users\\YOUR_NAME\\PycharmProjects\\pythonProject1\\venv\\Scripts\\shiping.py<\/code><\/p>\n\n\n\n<p>\u751f\u6210\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u67e5\u770b\u3002<\/p>\n\n\n\n<p>\u6211\u8fd9\u91cc\u5b58\u5728\u62a5\u9519<\/p>\n\n\n\n<p><code>AttributeError: module 'click' has no attribute 'get_args'<\/code><\/p>\n\n\n\n<p>\u53ef\u80fd\u662fclick\u6a21\u5757\u7248\u672c\u95ee\u9898\uff0c\u6d4b\u8bd5\u591a\u4e2a\u7248\u672c  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><noscript><img decoding=\"async\" width=\"1024\" height=\"52\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-1024x52.png\" alt class=\"wp-image-988\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-1024x52.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-300x15.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-768x39.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-1536x77.png 1536w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14.png 1849w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/noscript><img decoding=\"async\" width=\"1024\" height=\"52\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%2052%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-988 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%2052%22%3E%3C%2Fsvg%3E 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-1024x52.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-300x15.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-768x39.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-1536x77.png 1536w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14.png 1849w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/06\/image-14-1024x52.png\"><\/figure>\n\n\n\n<p>\u7f51\u4e0a\u6536\u4e0d\u5230\u89e3\u51b3\u529e\u6cd5\uff0c\u8fd9\u4e2a\u53ea\u80fd\u6162\u6162\u8c03\u8bd5\u4e86\uff0c\u5148\u8fd9\u6837\u3002\u9700\u8981\u6e90\u7801\u7684\u540c\u5b66\u79c1\u4fe1\u8054\u7cfb\u6211\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6253\u7b97\u5199\u4e00\u4e2a\u6709\u7f8e\u89c2GUI\u754c\u9762\u7684\u5b57\u7b26\u753b\u7a0b\u5e8f\uff0c\u76ee\u524dbug\u8fd8\u6ca1\u89e3\u51b3\uff0c\u6682\u65f6\u5728\u8fd9\u52a0\u4e2a\u4e66\u7b7e\u3002\u7531\u4e8e\u5199\u8fd9\u4e2a\u7a0b\u5e8f\u9700\u8981\u7684\u6a21\u5757\u6bd4\u8f83\u591a\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[14,10],"tags":[71,69,85],"class_list":["post-980","post","type-post","status-publish","format-standard","hentry","category-teacher","category-coding","tag-python","tag-learning","tag-exe","entry"],"_links":{"self":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/posts\/980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/comments?post=980"}],"version-history":[{"count":0,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/posts\/980\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/media?parent=980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/categories?post=980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/tags?post=980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}