[{"data":1,"prerenderedAt":1946},["ShallowReactive",2],{"tag-python":3},[4,323,1485],{"_path":5,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":9,"description":10,"date":11,"layout":12,"subtitle":13,"image":14,"optimized_image":14,"category":15,"tags":16,"author":18,"paginate":7,"body":19,"_type":317,"_id":318,"_source":319,"_file":320,"_stem":321,"_extension":322},"/posts/python-virtual-environments","posts",false,"","Python Virtual Environments (venv)","A Comprehensive Guide to Python Virtual Environments (venv)","2023-09-17 22:00:00","post","A Comprehensive Guide","/assets/img/uploads/python-image.jpg","code",[17,15],"python","jaimedearcos",{"type":20,"children":21,"toc":311},"root",[22,30,37,42,62,68,73,78,231,237,242,271,276,281,300,305],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27],{"type":28,"value":29},"text","In the world of Python development, managing dependencies can be a challenging task. You might encounter situations where different projects require different versions of the same library, or you simply want to isolate your project's environment to ensure consistency. That's where Python's venv comes into play. In this tutorial, we'll explore the advantages of using venv in your Python projects, guide you through its installation using pip, and provide an example of how to install dependencies and execute a Python script within your virtual environment.",{"type":23,"tag":31,"props":32,"children":34},"h2",{"id":33},"advantages-of-using-venv",[35],{"type":28,"value":36},"Advantages of Using venv",{"type":23,"tag":24,"props":38,"children":39},{},[40],{"type":28,"value":41},"Python's venv module, introduced in Python 3.3, allows you to create isolated Python environments for your projects. Here are some of the key advantages:",{"type":23,"tag":43,"props":44,"children":45},"ul",{},[46,52,57],{"type":23,"tag":47,"props":48,"children":49},"li",{},[50],{"type":28,"value":51},"Dependency Isolation: venv allows you to create a self-contained environment for each project. This means you can have different versions of Python and project-specific libraries without conflicts.",{"type":23,"tag":47,"props":53,"children":54},{},[55],{"type":28,"value":56},"Version Control Integration: Including your virtual environment in version control (e.g., Git) ensures that others can recreate your development environment precisely, making collaboration smoother.",{"type":23,"tag":47,"props":58,"children":59},{},[60],{"type":28,"value":61},"Easy Cleanup: Virtual environments are easy to create and delete, so you can keep your system clean by removing unused environments when you're done with a project.",{"type":23,"tag":31,"props":63,"children":65},{"id":64},"installing-venv-with-pip",[66],{"type":28,"value":67},"Installing venv with pip",{"type":23,"tag":24,"props":69,"children":70},{},[71],{"type":28,"value":72},"Before you can create virtual environments with venv, make sure you have Python 3.3 or higher installed on your system. Most modern Python installations come with venv included, so you don't need to install it separately.",{"type":23,"tag":24,"props":74,"children":75},{},[76],{"type":28,"value":77},"To create a new virtual environment, follow these steps:",{"type":23,"tag":79,"props":80,"children":81},"ol",{},[82,87,92,141],{"type":23,"tag":47,"props":83,"children":84},{},[85],{"type":28,"value":86},"Open your terminal or command prompt.",{"type":23,"tag":47,"props":88,"children":89},{},[90],{"type":28,"value":91},"Navigate to the directory where you want to create the virtual environment.",{"type":23,"tag":47,"props":93,"children":94},{},[95,97],{"type":28,"value":96},"Run the following command to create a new virtual environment named \"myenv\" (you can replace \"myenv\" with your preferred name):",{"type":23,"tag":98,"props":99,"children":103},"pre",{"className":100,"code":101,"language":102,"meta":8,"style":8},"language-bash shiki shiki-themes github-dark github-light","$ python -m venv myenv\n","bash",[104],{"type":23,"tag":15,"props":105,"children":106},{"__ignoreMap":8},[107],{"type":23,"tag":108,"props":109,"children":112},"span",{"class":110,"line":111},"line",1,[113,119,125,131,136],{"type":23,"tag":108,"props":114,"children":116},{"style":115},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[117],{"type":28,"value":118},"$",{"type":23,"tag":108,"props":120,"children":122},{"style":121},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[123],{"type":28,"value":124}," python",{"type":23,"tag":108,"props":126,"children":128},{"style":127},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[129],{"type":28,"value":130}," -m",{"type":23,"tag":108,"props":132,"children":133},{"style":121},[134],{"type":28,"value":135}," venv",{"type":23,"tag":108,"props":137,"children":138},{"style":121},[139],{"type":28,"value":140}," myenv\n",{"type":23,"tag":47,"props":142,"children":143},{},[144,146,154,193,201,225,229],{"type":28,"value":145},"To activate the virtual environment, use the appropriate command for your operating system:",{"type":23,"tag":43,"props":147,"children":148},{},[149],{"type":23,"tag":47,"props":150,"children":151},{},[152],{"type":28,"value":153},"On Windows:",{"type":23,"tag":98,"props":155,"children":157},{"className":100,"code":156,"language":102,"meta":8,"style":8},"$ myenv\\Scripts\\activate\n",[158],{"type":23,"tag":15,"props":159,"children":160},{"__ignoreMap":8},[161],{"type":23,"tag":108,"props":162,"children":163},{"class":110,"line":111},[164,168,173,178,183,188],{"type":23,"tag":108,"props":165,"children":166},{"style":115},[167],{"type":28,"value":118},{"type":23,"tag":108,"props":169,"children":170},{"style":121},[171],{"type":28,"value":172}," myenv",{"type":23,"tag":108,"props":174,"children":175},{"style":127},[176],{"type":28,"value":177},"\\S",{"type":23,"tag":108,"props":179,"children":180},{"style":121},[181],{"type":28,"value":182},"cripts",{"type":23,"tag":108,"props":184,"children":185},{"style":127},[186],{"type":28,"value":187},"\\a",{"type":23,"tag":108,"props":189,"children":190},{"style":121},[191],{"type":28,"value":192},"ctivate\n",{"type":23,"tag":43,"props":194,"children":195},{},[196],{"type":23,"tag":47,"props":197,"children":198},{},[199],{"type":28,"value":200},"On macOS and Linux:",{"type":23,"tag":98,"props":202,"children":204},{"className":100,"code":203,"language":102,"meta":8,"style":8},"$ source myenv/bin/activate\n",[205],{"type":23,"tag":15,"props":206,"children":207},{"__ignoreMap":8},[208],{"type":23,"tag":108,"props":209,"children":210},{"class":110,"line":111},[211,215,220],{"type":23,"tag":108,"props":212,"children":213},{"style":115},[214],{"type":28,"value":118},{"type":23,"tag":108,"props":216,"children":217},{"style":121},[218],{"type":28,"value":219}," source",{"type":23,"tag":108,"props":221,"children":222},{"style":121},[223],{"type":28,"value":224}," myenv/bin/activate\n",{"type":23,"tag":226,"props":227,"children":228},"br",{},[],{"type":28,"value":230},"Once activated, your terminal prompt will change, indicating that you are now working within the virtual environment.",{"type":23,"tag":31,"props":232,"children":234},{"id":233},"installing-dependencies-and-running-a-python-script",[235],{"type":28,"value":236},"Installing Dependencies and Running a Python Script",{"type":23,"tag":24,"props":238,"children":239},{},[240],{"type":28,"value":241},"Now that you're inside your virtual environment, you can install project-specific dependencies using pip. For example, let's install the popular library requests:",{"type":23,"tag":98,"props":243,"children":245},{"className":100,"code":244,"language":102,"meta":8,"style":8},"$ pip install requests\n",[246],{"type":23,"tag":15,"props":247,"children":248},{"__ignoreMap":8},[249],{"type":23,"tag":108,"props":250,"children":251},{"class":110,"line":111},[252,256,261,266],{"type":23,"tag":108,"props":253,"children":254},{"style":115},[255],{"type":28,"value":118},{"type":23,"tag":108,"props":257,"children":258},{"style":121},[259],{"type":28,"value":260}," pip",{"type":23,"tag":108,"props":262,"children":263},{"style":121},[264],{"type":28,"value":265}," install",{"type":23,"tag":108,"props":267,"children":268},{"style":121},[269],{"type":28,"value":270}," requests\n",{"type":23,"tag":24,"props":272,"children":273},{},[274],{"type":28,"value":275},"With your dependencies installed, you can create a Python script or use an existing one within the virtual environment. To run your script, simply execute it as you normally would. All the installed packages will be available for your script to use without affecting the global Python environment.",{"type":23,"tag":24,"props":277,"children":278},{},[279],{"type":28,"value":280},"When you're done working on your project, you can deactivate the virtual environment with the following command:",{"type":23,"tag":98,"props":282,"children":284},{"className":100,"code":283,"language":102,"meta":8,"style":8},"$ deactivate\n",[285],{"type":23,"tag":15,"props":286,"children":287},{"__ignoreMap":8},[288],{"type":23,"tag":108,"props":289,"children":290},{"class":110,"line":111},[291,295],{"type":23,"tag":108,"props":292,"children":293},{"style":115},[294],{"type":28,"value":118},{"type":23,"tag":108,"props":296,"children":297},{"style":121},[298],{"type":28,"value":299}," deactivate\n",{"type":23,"tag":24,"props":301,"children":302},{},[303],{"type":28,"value":304},"And that's it! You've successfully set up and used a virtual environment with venv in Python. This tool is invaluable for managing dependencies and keeping your projects organized. Incorporate venv into your Python development workflow to take full advantage of its benefits.",{"type":23,"tag":306,"props":307,"children":308},"style",{},[309],{"type":28,"value":310},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":8,"searchDepth":312,"depth":312,"links":313},2,[314,315,316],{"id":33,"depth":312,"text":36},{"id":64,"depth":312,"text":67},{"id":233,"depth":312,"text":236},"markdown","content:posts:python-virtual-environments.md","content","posts/python-virtual-environments.md","posts/python-virtual-environments","md",{"_path":324,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":325,"description":326,"date":327,"layout":12,"subtitle":326,"image":328,"optimized_image":328,"category":329,"tags":330,"author":18,"paginate":7,"body":333,"_type":317,"_id":1482,"_source":319,"_file":1483,"_stem":1484,"_extension":322},"/posts/how-to-create-a-twitter-bot","How to create a Twitter bot","Step by step creation of a twitter bot","2020-12-06T11:00:00.000Z","/assets/img/uploads/twitter.jpg","algorithms",[331,332,17],"bots","twitter",{"type":20,"children":334,"toc":1471},[335,341,353,366,374,381,387,399,458,470,682,687,706,712,717,727,859,865,889,895,1028,1034,1039,1057,1423,1434,1438,1444,1464,1467],{"type":23,"tag":31,"props":336,"children":338},{"id":337},"_1-request-your-developer-account-create-your-first-app",[339],{"type":28,"value":340},"1. Request your developer account & create your first app",{"type":23,"tag":24,"props":342,"children":343},{},[344,346],{"type":28,"value":345},"The first step of building twitter bots is to request access to developer features, this can be done easily\nin ",{"type":23,"tag":347,"props":348,"children":351},"a",{"href":349,"target":350},"developer.twitter.com","_blank",[352],{"type":28,"value":349},{"type":23,"tag":24,"props":354,"children":355},{},[356,358,364],{"type":28,"value":357},"Once you have fill the form to request access, you can log in the ",{"type":23,"tag":359,"props":360,"children":361},"strong",{},[362],{"type":28,"value":363},"twitter console",{"type":28,"value":365}," to retrieve the access keys:",{"type":23,"tag":24,"props":367,"children":368},{},[369],{"type":23,"tag":370,"props":371,"children":373},"img",{"alt":8,"src":372},"/assets/img/uploads/twitter-dashboard.png",[],{"type":23,"tag":24,"props":375,"children":376},{},[377],{"type":23,"tag":370,"props":378,"children":380},{"alt":8,"src":379},"/assets/img/uploads/twitter-tokens.png",[],{"type":23,"tag":31,"props":382,"children":384},{"id":383},"_2-set-up-dev-environment",[385],{"type":28,"value":386},"2. Set-up dev environment",{"type":23,"tag":24,"props":388,"children":389},{},[390,392,397],{"type":28,"value":391},"We are going to use ",{"type":23,"tag":359,"props":393,"children":394},{},[395],{"type":28,"value":396},"Tweepy",{"type":28,"value":398},", a python library to facilitate the communication with twitter API. To create the python\nenvironment and install Tweepy we need to execute the following commands:",{"type":23,"tag":98,"props":400,"children":402},{"className":100,"code":401,"language":102,"meta":8,"style":8},"python3 -m venv venv\nsource ./venv/bin/activate\npip install tweepy\n",[403],{"type":23,"tag":15,"props":404,"children":405},{"__ignoreMap":8},[406,427,440],{"type":23,"tag":108,"props":407,"children":408},{"class":110,"line":111},[409,414,418,422],{"type":23,"tag":108,"props":410,"children":411},{"style":115},[412],{"type":28,"value":413},"python3",{"type":23,"tag":108,"props":415,"children":416},{"style":127},[417],{"type":28,"value":130},{"type":23,"tag":108,"props":419,"children":420},{"style":121},[421],{"type":28,"value":135},{"type":23,"tag":108,"props":423,"children":424},{"style":121},[425],{"type":28,"value":426}," venv\n",{"type":23,"tag":108,"props":428,"children":429},{"class":110,"line":312},[430,435],{"type":23,"tag":108,"props":431,"children":432},{"style":127},[433],{"type":28,"value":434},"source",{"type":23,"tag":108,"props":436,"children":437},{"style":121},[438],{"type":28,"value":439}," ./venv/bin/activate\n",{"type":23,"tag":108,"props":441,"children":443},{"class":110,"line":442},3,[444,449,453],{"type":23,"tag":108,"props":445,"children":446},{"style":115},[447],{"type":28,"value":448},"pip",{"type":23,"tag":108,"props":450,"children":451},{"style":121},[452],{"type":28,"value":265},{"type":23,"tag":108,"props":454,"children":455},{"style":121},[456],{"type":28,"value":457}," tweepy\n",{"type":23,"tag":24,"props":459,"children":460},{},[461,463,468],{"type":28,"value":462},"After that we need to create our first python script to verify keys and environment (",{"type":23,"tag":359,"props":464,"children":465},{},[466],{"type":28,"value":467},"test-credentials.py",{"type":28,"value":469},")",{"type":23,"tag":98,"props":471,"children":474},{"className":472,"code":473,"language":17,"meta":8,"style":8},"language-python shiki shiki-themes github-dark github-light","import tweepy\n\n# Authentication\nauth = tweepy.OAuthHandler(\"CONSUMER_API_KEY\", \"CONSUMER_API_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"ACCESS_TOKEN_SECRET\")\napi = tweepy.API(auth)\n\ntry:\n    api.verify_credentials()\n    print(\"Authentication OK\")\nexcept:\n    print(\"Error during authentication\")\n",[475],{"type":23,"tag":15,"props":476,"children":477},{"__ignoreMap":8},[478,492,501,510,549,576,594,602,616,625,648,661],{"type":23,"tag":108,"props":479,"children":480},{"class":110,"line":111},[481,487],{"type":23,"tag":108,"props":482,"children":484},{"style":483},"--shiki-default:#F97583;--shiki-light:#D73A49",[485],{"type":28,"value":486},"import",{"type":23,"tag":108,"props":488,"children":490},{"style":489},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[491],{"type":28,"value":457},{"type":23,"tag":108,"props":493,"children":494},{"class":110,"line":312},[495],{"type":23,"tag":108,"props":496,"children":498},{"emptyLinePlaceholder":497},true,[499],{"type":28,"value":500},"\n",{"type":23,"tag":108,"props":502,"children":503},{"class":110,"line":442},[504],{"type":23,"tag":108,"props":505,"children":507},{"style":506},"--shiki-default:#6A737D;--shiki-light:#6A737D",[508],{"type":28,"value":509},"# Authentication\n",{"type":23,"tag":108,"props":511,"children":513},{"class":110,"line":512},4,[514,519,524,529,534,539,544],{"type":23,"tag":108,"props":515,"children":516},{"style":489},[517],{"type":28,"value":518},"auth ",{"type":23,"tag":108,"props":520,"children":521},{"style":483},[522],{"type":28,"value":523},"=",{"type":23,"tag":108,"props":525,"children":526},{"style":489},[527],{"type":28,"value":528}," tweepy.OAuthHandler(",{"type":23,"tag":108,"props":530,"children":531},{"style":121},[532],{"type":28,"value":533},"\"CONSUMER_API_KEY\"",{"type":23,"tag":108,"props":535,"children":536},{"style":489},[537],{"type":28,"value":538},", ",{"type":23,"tag":108,"props":540,"children":541},{"style":121},[542],{"type":28,"value":543},"\"CONSUMER_API_SECRET\"",{"type":23,"tag":108,"props":545,"children":546},{"style":489},[547],{"type":28,"value":548},")\n",{"type":23,"tag":108,"props":550,"children":552},{"class":110,"line":551},5,[553,558,563,567,572],{"type":23,"tag":108,"props":554,"children":555},{"style":489},[556],{"type":28,"value":557},"auth.set_access_token(",{"type":23,"tag":108,"props":559,"children":560},{"style":121},[561],{"type":28,"value":562},"\"ACCESS_TOKEN\"",{"type":23,"tag":108,"props":564,"children":565},{"style":489},[566],{"type":28,"value":538},{"type":23,"tag":108,"props":568,"children":569},{"style":121},[570],{"type":28,"value":571},"\"ACCESS_TOKEN_SECRET\"",{"type":23,"tag":108,"props":573,"children":574},{"style":489},[575],{"type":28,"value":548},{"type":23,"tag":108,"props":577,"children":579},{"class":110,"line":578},6,[580,585,589],{"type":23,"tag":108,"props":581,"children":582},{"style":489},[583],{"type":28,"value":584},"api ",{"type":23,"tag":108,"props":586,"children":587},{"style":483},[588],{"type":28,"value":523},{"type":23,"tag":108,"props":590,"children":591},{"style":489},[592],{"type":28,"value":593}," tweepy.API(auth)\n",{"type":23,"tag":108,"props":595,"children":597},{"class":110,"line":596},7,[598],{"type":23,"tag":108,"props":599,"children":600},{"emptyLinePlaceholder":497},[601],{"type":28,"value":500},{"type":23,"tag":108,"props":603,"children":605},{"class":110,"line":604},8,[606,611],{"type":23,"tag":108,"props":607,"children":608},{"style":483},[609],{"type":28,"value":610},"try",{"type":23,"tag":108,"props":612,"children":613},{"style":489},[614],{"type":28,"value":615},":\n",{"type":23,"tag":108,"props":617,"children":619},{"class":110,"line":618},9,[620],{"type":23,"tag":108,"props":621,"children":622},{"style":489},[623],{"type":28,"value":624},"    api.verify_credentials()\n",{"type":23,"tag":108,"props":626,"children":628},{"class":110,"line":627},10,[629,634,639,644],{"type":23,"tag":108,"props":630,"children":631},{"style":127},[632],{"type":28,"value":633},"    print",{"type":23,"tag":108,"props":635,"children":636},{"style":489},[637],{"type":28,"value":638},"(",{"type":23,"tag":108,"props":640,"children":641},{"style":121},[642],{"type":28,"value":643},"\"Authentication OK\"",{"type":23,"tag":108,"props":645,"children":646},{"style":489},[647],{"type":28,"value":548},{"type":23,"tag":108,"props":649,"children":651},{"class":110,"line":650},11,[652,657],{"type":23,"tag":108,"props":653,"children":654},{"style":483},[655],{"type":28,"value":656},"except",{"type":23,"tag":108,"props":658,"children":659},{"style":489},[660],{"type":28,"value":615},{"type":23,"tag":108,"props":662,"children":664},{"class":110,"line":663},12,[665,669,673,678],{"type":23,"tag":108,"props":666,"children":667},{"style":127},[668],{"type":28,"value":633},{"type":23,"tag":108,"props":670,"children":671},{"style":489},[672],{"type":28,"value":638},{"type":23,"tag":108,"props":674,"children":675},{"style":121},[676],{"type":28,"value":677},"\"Error during authentication\"",{"type":23,"tag":108,"props":679,"children":680},{"style":489},[681],{"type":28,"value":548},{"type":23,"tag":24,"props":683,"children":684},{},[685],{"type":28,"value":686},"Run the script by executing:",{"type":23,"tag":98,"props":688,"children":690},{"className":100,"code":689,"language":102,"meta":8,"style":8},"python test-credentials.py  \n",[691],{"type":23,"tag":15,"props":692,"children":693},{"__ignoreMap":8},[694],{"type":23,"tag":108,"props":695,"children":696},{"class":110,"line":111},[697,701],{"type":23,"tag":108,"props":698,"children":699},{"style":115},[700],{"type":28,"value":17},{"type":23,"tag":108,"props":702,"children":703},{"style":121},[704],{"type":28,"value":705}," test-credentials.py\n",{"type":23,"tag":31,"props":707,"children":709},{"id":708},"_3-playing-with-the-api",[710],{"type":28,"value":711},"3. Playing with the API",{"type":23,"tag":24,"props":713,"children":714},{},[715],{"type":28,"value":716},"Tweepy provides a really simple way to retrieve/create twitter information.",{"type":23,"tag":718,"props":719,"children":721},"h3",{"id":720},"retrieve-your-timeline",[722],{"type":23,"tag":359,"props":723,"children":724},{},[725],{"type":28,"value":726},"Retrieve your timeline",{"type":23,"tag":98,"props":728,"children":730},{"className":472,"code":729,"language":17,"meta":8,"style":8},"# ...\n\n# Retrieve timeline\ntimeline = api.home_timeline()\nfor tweet in timeline:\n    print(f\"{tweet.user.name} said {tweet.text}\")\n",[731],{"type":23,"tag":15,"props":732,"children":733},{"__ignoreMap":8},[734,742,749,757,774,797],{"type":23,"tag":108,"props":735,"children":736},{"class":110,"line":111},[737],{"type":23,"tag":108,"props":738,"children":739},{"style":506},[740],{"type":28,"value":741},"# ...\n",{"type":23,"tag":108,"props":743,"children":744},{"class":110,"line":312},[745],{"type":23,"tag":108,"props":746,"children":747},{"emptyLinePlaceholder":497},[748],{"type":28,"value":500},{"type":23,"tag":108,"props":750,"children":751},{"class":110,"line":442},[752],{"type":23,"tag":108,"props":753,"children":754},{"style":506},[755],{"type":28,"value":756},"# Retrieve timeline\n",{"type":23,"tag":108,"props":758,"children":759},{"class":110,"line":512},[760,765,769],{"type":23,"tag":108,"props":761,"children":762},{"style":489},[763],{"type":28,"value":764},"timeline ",{"type":23,"tag":108,"props":766,"children":767},{"style":483},[768],{"type":28,"value":523},{"type":23,"tag":108,"props":770,"children":771},{"style":489},[772],{"type":28,"value":773}," api.home_timeline()\n",{"type":23,"tag":108,"props":775,"children":776},{"class":110,"line":551},[777,782,787,792],{"type":23,"tag":108,"props":778,"children":779},{"style":483},[780],{"type":28,"value":781},"for",{"type":23,"tag":108,"props":783,"children":784},{"style":489},[785],{"type":28,"value":786}," tweet ",{"type":23,"tag":108,"props":788,"children":789},{"style":483},[790],{"type":28,"value":791},"in",{"type":23,"tag":108,"props":793,"children":794},{"style":489},[795],{"type":28,"value":796}," timeline:\n",{"type":23,"tag":108,"props":798,"children":799},{"class":110,"line":578},[800,804,808,813,818,823,828,833,838,842,847,851,855],{"type":23,"tag":108,"props":801,"children":802},{"style":127},[803],{"type":28,"value":633},{"type":23,"tag":108,"props":805,"children":806},{"style":489},[807],{"type":28,"value":638},{"type":23,"tag":108,"props":809,"children":810},{"style":483},[811],{"type":28,"value":812},"f",{"type":23,"tag":108,"props":814,"children":815},{"style":121},[816],{"type":28,"value":817},"\"",{"type":23,"tag":108,"props":819,"children":820},{"style":127},[821],{"type":28,"value":822},"{",{"type":23,"tag":108,"props":824,"children":825},{"style":489},[826],{"type":28,"value":827},"tweet.user.name",{"type":23,"tag":108,"props":829,"children":830},{"style":127},[831],{"type":28,"value":832},"}",{"type":23,"tag":108,"props":834,"children":835},{"style":121},[836],{"type":28,"value":837}," said ",{"type":23,"tag":108,"props":839,"children":840},{"style":127},[841],{"type":28,"value":822},{"type":23,"tag":108,"props":843,"children":844},{"style":489},[845],{"type":28,"value":846},"tweet.text",{"type":23,"tag":108,"props":848,"children":849},{"style":127},[850],{"type":28,"value":832},{"type":23,"tag":108,"props":852,"children":853},{"style":121},[854],{"type":28,"value":817},{"type":23,"tag":108,"props":856,"children":857},{"style":489},[858],{"type":28,"value":548},{"type":23,"tag":718,"props":860,"children":862},{"id":861},"publish-a-new-tweet",[863],{"type":28,"value":864},"Publish a new tweet",{"type":23,"tag":98,"props":866,"children":868},{"className":472,"code":867,"language":17,"meta":8,"style":8},"api.update_status(\"Hello World from Tweepy\")\n",[869],{"type":23,"tag":15,"props":870,"children":871},{"__ignoreMap":8},[872],{"type":23,"tag":108,"props":873,"children":874},{"class":110,"line":111},[875,880,885],{"type":23,"tag":108,"props":876,"children":877},{"style":489},[878],{"type":28,"value":879},"api.update_status(",{"type":23,"tag":108,"props":881,"children":882},{"style":121},[883],{"type":28,"value":884},"\"Hello World from Tweepy\"",{"type":23,"tag":108,"props":886,"children":887},{"style":489},[888],{"type":28,"value":548},{"type":23,"tag":718,"props":890,"children":892},{"id":891},"retrieve-info-of-any-user",[893],{"type":28,"value":894},"Retrieve info of any user",{"type":23,"tag":98,"props":896,"children":898},{"className":472,"code":897,"language":17,"meta":8,"style":8},"user = api.get_user(\"JaimeDeArcos\")\n\nprint(\"User details:\")\nprint(user)\n\nprint(\"Last 20 Followers:\")\nfor follower in user.followers():\n    print(follower.name)\n",[899],{"type":23,"tag":15,"props":900,"children":901},{"__ignoreMap":8},[902,928,935,956,968,975,995,1016],{"type":23,"tag":108,"props":903,"children":904},{"class":110,"line":111},[905,910,914,919,924],{"type":23,"tag":108,"props":906,"children":907},{"style":489},[908],{"type":28,"value":909},"user ",{"type":23,"tag":108,"props":911,"children":912},{"style":483},[913],{"type":28,"value":523},{"type":23,"tag":108,"props":915,"children":916},{"style":489},[917],{"type":28,"value":918}," api.get_user(",{"type":23,"tag":108,"props":920,"children":921},{"style":121},[922],{"type":28,"value":923},"\"JaimeDeArcos\"",{"type":23,"tag":108,"props":925,"children":926},{"style":489},[927],{"type":28,"value":548},{"type":23,"tag":108,"props":929,"children":930},{"class":110,"line":312},[931],{"type":23,"tag":108,"props":932,"children":933},{"emptyLinePlaceholder":497},[934],{"type":28,"value":500},{"type":23,"tag":108,"props":936,"children":937},{"class":110,"line":442},[938,943,947,952],{"type":23,"tag":108,"props":939,"children":940},{"style":127},[941],{"type":28,"value":942},"print",{"type":23,"tag":108,"props":944,"children":945},{"style":489},[946],{"type":28,"value":638},{"type":23,"tag":108,"props":948,"children":949},{"style":121},[950],{"type":28,"value":951},"\"User details:\"",{"type":23,"tag":108,"props":953,"children":954},{"style":489},[955],{"type":28,"value":548},{"type":23,"tag":108,"props":957,"children":958},{"class":110,"line":512},[959,963],{"type":23,"tag":108,"props":960,"children":961},{"style":127},[962],{"type":28,"value":942},{"type":23,"tag":108,"props":964,"children":965},{"style":489},[966],{"type":28,"value":967},"(user)\n",{"type":23,"tag":108,"props":969,"children":970},{"class":110,"line":551},[971],{"type":23,"tag":108,"props":972,"children":973},{"emptyLinePlaceholder":497},[974],{"type":28,"value":500},{"type":23,"tag":108,"props":976,"children":977},{"class":110,"line":578},[978,982,986,991],{"type":23,"tag":108,"props":979,"children":980},{"style":127},[981],{"type":28,"value":942},{"type":23,"tag":108,"props":983,"children":984},{"style":489},[985],{"type":28,"value":638},{"type":23,"tag":108,"props":987,"children":988},{"style":121},[989],{"type":28,"value":990},"\"Last 20 Followers:\"",{"type":23,"tag":108,"props":992,"children":993},{"style":489},[994],{"type":28,"value":548},{"type":23,"tag":108,"props":996,"children":997},{"class":110,"line":596},[998,1002,1007,1011],{"type":23,"tag":108,"props":999,"children":1000},{"style":483},[1001],{"type":28,"value":781},{"type":23,"tag":108,"props":1003,"children":1004},{"style":489},[1005],{"type":28,"value":1006}," follower ",{"type":23,"tag":108,"props":1008,"children":1009},{"style":483},[1010],{"type":28,"value":791},{"type":23,"tag":108,"props":1012,"children":1013},{"style":489},[1014],{"type":28,"value":1015}," user.followers():\n",{"type":23,"tag":108,"props":1017,"children":1018},{"class":110,"line":604},[1019,1023],{"type":23,"tag":108,"props":1020,"children":1021},{"style":127},[1022],{"type":28,"value":633},{"type":23,"tag":108,"props":1024,"children":1025},{"style":489},[1026],{"type":28,"value":1027},"(follower.name)\n",{"type":23,"tag":31,"props":1029,"children":1031},{"id":1030},"creating-your-first-bot-follow-anyone-who-follows-you",[1032],{"type":28,"value":1033},"Creating your first bot - Follow anyone who follows you",{"type":23,"tag":24,"props":1035,"children":1036},{},[1037],{"type":28,"value":1038},"In this example we are going to create a bot which:",{"type":23,"tag":43,"props":1040,"children":1041},{},[1042,1047,1052],{"type":23,"tag":47,"props":1043,"children":1044},{},[1045],{"type":28,"value":1046},"Retrieve the list of your followers",{"type":23,"tag":47,"props":1048,"children":1049},{},[1050],{"type":28,"value":1051},"Check if you're already following them",{"type":23,"tag":47,"props":1053,"children":1054},{},[1055],{"type":28,"value":1056},"If not, start following",{"type":23,"tag":98,"props":1058,"children":1060},{"className":472,"code":1059,"language":17,"meta":8,"style":8},"import tweepy, time\n\n# Authentication\nauth = tweepy.OAuthHandler(\"CONSUMER_API_KEY\", \"CONSUMER_API_SECRET\")\nauth.set_access_token(\"ACCESS_TOKEN\", \"ACCESS_TOKEN_SECRET\")\napi = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)\n\n# Verify authentication\ntry:\n    api.verify_credentials()\n    print(\"Authentication OK\")\nexcept:\n    print(\"Error during authentication\")\n\nwhile True:\n    # Retrieve followers\n    for follower in tweepy.Cursor(api.followers).items():\n        if not follower.following:\n            print(\"New Follower -> {}\".format(follower.name))\n            follower.follow()\n    # Sleep for 2 minutes \n    time.sleep(120)\n\n",[1061],{"type":23,"tag":15,"props":1062,"children":1063},{"__ignoreMap":8},[1064,1076,1083,1090,1121,1144,1196,1203,1211,1222,1229,1248,1259,1279,1287,1305,1314,1336,1355,1387,1396,1405],{"type":23,"tag":108,"props":1065,"children":1066},{"class":110,"line":111},[1067,1071],{"type":23,"tag":108,"props":1068,"children":1069},{"style":483},[1070],{"type":28,"value":486},{"type":23,"tag":108,"props":1072,"children":1073},{"style":489},[1074],{"type":28,"value":1075}," tweepy, time\n",{"type":23,"tag":108,"props":1077,"children":1078},{"class":110,"line":312},[1079],{"type":23,"tag":108,"props":1080,"children":1081},{"emptyLinePlaceholder":497},[1082],{"type":28,"value":500},{"type":23,"tag":108,"props":1084,"children":1085},{"class":110,"line":442},[1086],{"type":23,"tag":108,"props":1087,"children":1088},{"style":506},[1089],{"type":28,"value":509},{"type":23,"tag":108,"props":1091,"children":1092},{"class":110,"line":512},[1093,1097,1101,1105,1109,1113,1117],{"type":23,"tag":108,"props":1094,"children":1095},{"style":489},[1096],{"type":28,"value":518},{"type":23,"tag":108,"props":1098,"children":1099},{"style":483},[1100],{"type":28,"value":523},{"type":23,"tag":108,"props":1102,"children":1103},{"style":489},[1104],{"type":28,"value":528},{"type":23,"tag":108,"props":1106,"children":1107},{"style":121},[1108],{"type":28,"value":533},{"type":23,"tag":108,"props":1110,"children":1111},{"style":489},[1112],{"type":28,"value":538},{"type":23,"tag":108,"props":1114,"children":1115},{"style":121},[1116],{"type":28,"value":543},{"type":23,"tag":108,"props":1118,"children":1119},{"style":489},[1120],{"type":28,"value":548},{"type":23,"tag":108,"props":1122,"children":1123},{"class":110,"line":551},[1124,1128,1132,1136,1140],{"type":23,"tag":108,"props":1125,"children":1126},{"style":489},[1127],{"type":28,"value":557},{"type":23,"tag":108,"props":1129,"children":1130},{"style":121},[1131],{"type":28,"value":562},{"type":23,"tag":108,"props":1133,"children":1134},{"style":489},[1135],{"type":28,"value":538},{"type":23,"tag":108,"props":1137,"children":1138},{"style":121},[1139],{"type":28,"value":571},{"type":23,"tag":108,"props":1141,"children":1142},{"style":489},[1143],{"type":28,"value":548},{"type":23,"tag":108,"props":1145,"children":1146},{"class":110,"line":578},[1147,1151,1155,1160,1166,1170,1175,1179,1184,1188,1192],{"type":23,"tag":108,"props":1148,"children":1149},{"style":489},[1150],{"type":28,"value":584},{"type":23,"tag":108,"props":1152,"children":1153},{"style":483},[1154],{"type":28,"value":523},{"type":23,"tag":108,"props":1156,"children":1157},{"style":489},[1158],{"type":28,"value":1159}," tweepy.API(auth, ",{"type":23,"tag":108,"props":1161,"children":1163},{"style":1162},"--shiki-default:#FFAB70;--shiki-light:#E36209",[1164],{"type":28,"value":1165},"wait_on_rate_limit",{"type":23,"tag":108,"props":1167,"children":1168},{"style":483},[1169],{"type":28,"value":523},{"type":23,"tag":108,"props":1171,"children":1172},{"style":127},[1173],{"type":28,"value":1174},"True",{"type":23,"tag":108,"props":1176,"children":1177},{"style":489},[1178],{"type":28,"value":538},{"type":23,"tag":108,"props":1180,"children":1181},{"style":1162},[1182],{"type":28,"value":1183},"wait_on_rate_limit_notify",{"type":23,"tag":108,"props":1185,"children":1186},{"style":483},[1187],{"type":28,"value":523},{"type":23,"tag":108,"props":1189,"children":1190},{"style":127},[1191],{"type":28,"value":1174},{"type":23,"tag":108,"props":1193,"children":1194},{"style":489},[1195],{"type":28,"value":548},{"type":23,"tag":108,"props":1197,"children":1198},{"class":110,"line":596},[1199],{"type":23,"tag":108,"props":1200,"children":1201},{"emptyLinePlaceholder":497},[1202],{"type":28,"value":500},{"type":23,"tag":108,"props":1204,"children":1205},{"class":110,"line":604},[1206],{"type":23,"tag":108,"props":1207,"children":1208},{"style":506},[1209],{"type":28,"value":1210},"# Verify authentication\n",{"type":23,"tag":108,"props":1212,"children":1213},{"class":110,"line":618},[1214,1218],{"type":23,"tag":108,"props":1215,"children":1216},{"style":483},[1217],{"type":28,"value":610},{"type":23,"tag":108,"props":1219,"children":1220},{"style":489},[1221],{"type":28,"value":615},{"type":23,"tag":108,"props":1223,"children":1224},{"class":110,"line":627},[1225],{"type":23,"tag":108,"props":1226,"children":1227},{"style":489},[1228],{"type":28,"value":624},{"type":23,"tag":108,"props":1230,"children":1231},{"class":110,"line":650},[1232,1236,1240,1244],{"type":23,"tag":108,"props":1233,"children":1234},{"style":127},[1235],{"type":28,"value":633},{"type":23,"tag":108,"props":1237,"children":1238},{"style":489},[1239],{"type":28,"value":638},{"type":23,"tag":108,"props":1241,"children":1242},{"style":121},[1243],{"type":28,"value":643},{"type":23,"tag":108,"props":1245,"children":1246},{"style":489},[1247],{"type":28,"value":548},{"type":23,"tag":108,"props":1249,"children":1250},{"class":110,"line":663},[1251,1255],{"type":23,"tag":108,"props":1252,"children":1253},{"style":483},[1254],{"type":28,"value":656},{"type":23,"tag":108,"props":1256,"children":1257},{"style":489},[1258],{"type":28,"value":615},{"type":23,"tag":108,"props":1260,"children":1262},{"class":110,"line":1261},13,[1263,1267,1271,1275],{"type":23,"tag":108,"props":1264,"children":1265},{"style":127},[1266],{"type":28,"value":633},{"type":23,"tag":108,"props":1268,"children":1269},{"style":489},[1270],{"type":28,"value":638},{"type":23,"tag":108,"props":1272,"children":1273},{"style":121},[1274],{"type":28,"value":677},{"type":23,"tag":108,"props":1276,"children":1277},{"style":489},[1278],{"type":28,"value":548},{"type":23,"tag":108,"props":1280,"children":1282},{"class":110,"line":1281},14,[1283],{"type":23,"tag":108,"props":1284,"children":1285},{"emptyLinePlaceholder":497},[1286],{"type":28,"value":500},{"type":23,"tag":108,"props":1288,"children":1290},{"class":110,"line":1289},15,[1291,1296,1301],{"type":23,"tag":108,"props":1292,"children":1293},{"style":483},[1294],{"type":28,"value":1295},"while",{"type":23,"tag":108,"props":1297,"children":1298},{"style":127},[1299],{"type":28,"value":1300}," True",{"type":23,"tag":108,"props":1302,"children":1303},{"style":489},[1304],{"type":28,"value":615},{"type":23,"tag":108,"props":1306,"children":1308},{"class":110,"line":1307},16,[1309],{"type":23,"tag":108,"props":1310,"children":1311},{"style":506},[1312],{"type":28,"value":1313},"    # Retrieve followers\n",{"type":23,"tag":108,"props":1315,"children":1317},{"class":110,"line":1316},17,[1318,1323,1327,1331],{"type":23,"tag":108,"props":1319,"children":1320},{"style":483},[1321],{"type":28,"value":1322},"    for",{"type":23,"tag":108,"props":1324,"children":1325},{"style":489},[1326],{"type":28,"value":1006},{"type":23,"tag":108,"props":1328,"children":1329},{"style":483},[1330],{"type":28,"value":791},{"type":23,"tag":108,"props":1332,"children":1333},{"style":489},[1334],{"type":28,"value":1335}," tweepy.Cursor(api.followers).items():\n",{"type":23,"tag":108,"props":1337,"children":1339},{"class":110,"line":1338},18,[1340,1345,1350],{"type":23,"tag":108,"props":1341,"children":1342},{"style":483},[1343],{"type":28,"value":1344},"        if",{"type":23,"tag":108,"props":1346,"children":1347},{"style":483},[1348],{"type":28,"value":1349}," not",{"type":23,"tag":108,"props":1351,"children":1352},{"style":489},[1353],{"type":28,"value":1354}," follower.following:\n",{"type":23,"tag":108,"props":1356,"children":1358},{"class":110,"line":1357},19,[1359,1364,1368,1373,1378,1382],{"type":23,"tag":108,"props":1360,"children":1361},{"style":127},[1362],{"type":28,"value":1363},"            print",{"type":23,"tag":108,"props":1365,"children":1366},{"style":489},[1367],{"type":28,"value":638},{"type":23,"tag":108,"props":1369,"children":1370},{"style":121},[1371],{"type":28,"value":1372},"\"New Follower -> ",{"type":23,"tag":108,"props":1374,"children":1375},{"style":127},[1376],{"type":28,"value":1377},"{}",{"type":23,"tag":108,"props":1379,"children":1380},{"style":121},[1381],{"type":28,"value":817},{"type":23,"tag":108,"props":1383,"children":1384},{"style":489},[1385],{"type":28,"value":1386},".format(follower.name))\n",{"type":23,"tag":108,"props":1388,"children":1390},{"class":110,"line":1389},20,[1391],{"type":23,"tag":108,"props":1392,"children":1393},{"style":489},[1394],{"type":28,"value":1395},"            follower.follow()\n",{"type":23,"tag":108,"props":1397,"children":1399},{"class":110,"line":1398},21,[1400],{"type":23,"tag":108,"props":1401,"children":1402},{"style":506},[1403],{"type":28,"value":1404},"    # Sleep for 2 minutes \n",{"type":23,"tag":108,"props":1406,"children":1408},{"class":110,"line":1407},22,[1409,1414,1419],{"type":23,"tag":108,"props":1410,"children":1411},{"style":489},[1412],{"type":28,"value":1413},"    time.sleep(",{"type":23,"tag":108,"props":1415,"children":1416},{"style":127},[1417],{"type":28,"value":1418},"120",{"type":23,"tag":108,"props":1420,"children":1421},{"style":489},[1422],{"type":28,"value":548},{"type":23,"tag":24,"props":1424,"children":1425},{},[1426,1428],{"type":28,"value":1427},"Simple, right? now you can improve the script with whatever use case you need. This script could be running locally or\nmaybe you would deploy it on any provider of your choice ",{"type":23,"tag":1429,"props":1430,"children":1431},"em",{},[1432],{"type":28,"value":1433},"(AWS, Azure, google cloud...)",{"type":23,"tag":1435,"props":1436,"children":1437},"hr",{},[],{"type":23,"tag":31,"props":1439,"children":1441},{"id":1440},"references-links",[1442],{"type":28,"value":1443},"References & links",{"type":23,"tag":43,"props":1445,"children":1446},{},[1447,1454],{"type":23,"tag":47,"props":1448,"children":1449},{},[1450],{"type":23,"tag":347,"props":1451,"children":1452},{"href":349},[1453],{"type":28,"value":349},{"type":23,"tag":47,"props":1455,"children":1456},{},[1457],{"type":23,"tag":347,"props":1458,"children":1462},{"href":1459,"rel":1460},"https://www.tweepy.org/",[1461],"nofollow",[1463],{"type":28,"value":396},{"type":23,"tag":1435,"props":1465,"children":1466},{},[],{"type":23,"tag":306,"props":1468,"children":1469},{},[1470],{"type":28,"value":310},{"title":8,"searchDepth":312,"depth":312,"links":1472},[1473,1474,1475,1480,1481],{"id":337,"depth":312,"text":340},{"id":383,"depth":312,"text":386},{"id":708,"depth":312,"text":711,"children":1476},[1477,1478,1479],{"id":720,"depth":442,"text":726},{"id":861,"depth":442,"text":864},{"id":891,"depth":442,"text":894},{"id":1030,"depth":312,"text":1033},{"id":1440,"depth":312,"text":1443},"content:posts:how-to-create-a-twitter-bot.md","posts/how-to-create-a-twitter-bot.md","posts/how-to-create-a-twitter-bot",{"_path":1486,"_dir":6,"_draft":7,"_partial":7,"_locale":8,"title":1487,"description":1488,"date":1489,"layout":12,"subtitle":1490,"image":1491,"optimized_image":1491,"category":15,"tags":1492,"author":18,"paginate":7,"body":1494,"_type":317,"_id":1943,"_source":319,"_file":1944,"_stem":1945,"_extension":322},"/posts/playing-with-ocr-libraries","Playing with OCR libraries","How to recognize text from images with pytesseract library. From image to python string","2020-11-22T11:00:00.000Z","How to recognize text from images with pytesseract library","/assets/img/uploads/ocr.jpg",[1493,17],"ocr",{"type":20,"children":1495,"toc":1938},[1496,1509,1515,1536,1562,1567,1627,1632,1673,1679,1904,1916,1922,1934],{"type":23,"tag":24,"props":1497,"children":1498},{},[1499,1501,1507],{"type":28,"value":1500},"A Few days ago I found a cool library for text recognition in images, ",{"type":23,"tag":347,"props":1502,"children":1504},{"href":1503},"https://pypi.org/project/pytesseract/",[1505],{"type":28,"value":1506},"pytesseract",{"type":28,"value":1508},".\nWith this library and just a few lines of code you can implement OCR features.",{"type":23,"tag":31,"props":1510,"children":1512},{"id":1511},"get-started",[1513],{"type":28,"value":1514},"Get started",{"type":23,"tag":24,"props":1516,"children":1517},{},[1518,1520,1526,1528,1535],{"type":28,"value":1519},"Install ",{"type":23,"tag":15,"props":1521,"children":1523},{"className":1522},[],[1524],{"type":28,"value":1525},"teseract",{"type":28,"value":1527}," in MacOs (",{"type":23,"tag":347,"props":1529,"children":1532},{"href":1530,"rel":1531},"https://tesseract-ocr.github.io/tessdoc/Home.html",[1461],[1533],{"type":28,"value":1534},"for other platforms",{"type":28,"value":469},{"type":23,"tag":98,"props":1537,"children":1541},{"className":1538,"code":1539,"language":1540,"meta":8,"style":8},"language-sh shiki shiki-themes github-dark github-light","brew install tesseract\n","sh",[1542],{"type":23,"tag":15,"props":1543,"children":1544},{"__ignoreMap":8},[1545],{"type":23,"tag":108,"props":1546,"children":1547},{"class":110,"line":111},[1548,1553,1557],{"type":23,"tag":108,"props":1549,"children":1550},{"style":115},[1551],{"type":28,"value":1552},"brew",{"type":23,"tag":108,"props":1554,"children":1555},{"style":121},[1556],{"type":28,"value":265},{"type":23,"tag":108,"props":1558,"children":1559},{"style":121},[1560],{"type":28,"value":1561}," tesseract\n",{"type":23,"tag":24,"props":1563,"children":1564},{},[1565],{"type":28,"value":1566},"Create a new python environment & install requirements",{"type":23,"tag":98,"props":1568,"children":1570},{"className":100,"code":1569,"language":102,"meta":8,"style":8},"python -m venv en\nsource env/bin/activate\npip install -r requirements.txt\n",[1571],{"type":23,"tag":15,"props":1572,"children":1573},{"__ignoreMap":8},[1574,1594,1606],{"type":23,"tag":108,"props":1575,"children":1576},{"class":110,"line":111},[1577,1581,1585,1589],{"type":23,"tag":108,"props":1578,"children":1579},{"style":115},[1580],{"type":28,"value":17},{"type":23,"tag":108,"props":1582,"children":1583},{"style":127},[1584],{"type":28,"value":130},{"type":23,"tag":108,"props":1586,"children":1587},{"style":121},[1588],{"type":28,"value":135},{"type":23,"tag":108,"props":1590,"children":1591},{"style":121},[1592],{"type":28,"value":1593}," en\n",{"type":23,"tag":108,"props":1595,"children":1596},{"class":110,"line":312},[1597,1601],{"type":23,"tag":108,"props":1598,"children":1599},{"style":127},[1600],{"type":28,"value":434},{"type":23,"tag":108,"props":1602,"children":1603},{"style":121},[1604],{"type":28,"value":1605}," env/bin/activate\n",{"type":23,"tag":108,"props":1607,"children":1608},{"class":110,"line":442},[1609,1613,1617,1622],{"type":23,"tag":108,"props":1610,"children":1611},{"style":115},[1612],{"type":28,"value":448},{"type":23,"tag":108,"props":1614,"children":1615},{"style":121},[1616],{"type":28,"value":265},{"type":23,"tag":108,"props":1618,"children":1619},{"style":127},[1620],{"type":28,"value":1621}," -r",{"type":23,"tag":108,"props":1623,"children":1624},{"style":121},[1625],{"type":28,"value":1626}," requirements.txt\n",{"type":23,"tag":24,"props":1628,"children":1629},{},[1630],{"type":28,"value":1631},"requirements.txt file",{"type":23,"tag":98,"props":1633,"children":1637},{"className":1634,"code":1635,"language":1636,"meta":8,"style":8},"language-txt shiki shiki-themes github-dark github-light","numpy==1.19.4\nopencv-python==4.4.0.46\nPillow==8.0.1\npytesseract==0.3.6\n","txt",[1638],{"type":23,"tag":15,"props":1639,"children":1640},{"__ignoreMap":8},[1641,1649,1657,1665],{"type":23,"tag":108,"props":1642,"children":1643},{"class":110,"line":111},[1644],{"type":23,"tag":108,"props":1645,"children":1646},{},[1647],{"type":28,"value":1648},"numpy==1.19.4\n",{"type":23,"tag":108,"props":1650,"children":1651},{"class":110,"line":312},[1652],{"type":23,"tag":108,"props":1653,"children":1654},{},[1655],{"type":28,"value":1656},"opencv-python==4.4.0.46\n",{"type":23,"tag":108,"props":1658,"children":1659},{"class":110,"line":442},[1660],{"type":23,"tag":108,"props":1661,"children":1662},{},[1663],{"type":28,"value":1664},"Pillow==8.0.1\n",{"type":23,"tag":108,"props":1666,"children":1667},{"class":110,"line":512},[1668],{"type":23,"tag":108,"props":1669,"children":1670},{},[1671],{"type":28,"value":1672},"pytesseract==0.3.6\n",{"type":23,"tag":31,"props":1674,"children":1676},{"id":1675},"create-your-first-ocr-script",[1677],{"type":28,"value":1678},"Create your first ocr script",{"type":23,"tag":98,"props":1680,"children":1682},{"className":472,"code":1681,"language":17,"meta":8,"style":8},"from PIL import Image\nimport pytesseract\nimport argparse\nimport sys\n\noriginal_image = \"image.jpg\"\nimage = cv2.imread(original_image)\ngray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n\n# Convert to grayscale for better performance\nfilename = \"grayscale_image.png\"\ncv2.imwrite(filename, gray)\n\n# Load the image as a PIL/Pillow image and apply OCR\ntext = pytesseract.image_to_string(Image.open(filename))\nos.remove(filename)\nprint(text)\n",[1683],{"type":23,"tag":15,"props":1684,"children":1685},{"__ignoreMap":8},[1686,1709,1721,1733,1745,1752,1769,1786,1812,1819,1827,1844,1852,1859,1867,1884,1892],{"type":23,"tag":108,"props":1687,"children":1688},{"class":110,"line":111},[1689,1694,1699,1704],{"type":23,"tag":108,"props":1690,"children":1691},{"style":483},[1692],{"type":28,"value":1693},"from",{"type":23,"tag":108,"props":1695,"children":1696},{"style":127},[1697],{"type":28,"value":1698}," PIL",{"type":23,"tag":108,"props":1700,"children":1701},{"style":483},[1702],{"type":28,"value":1703}," import",{"type":23,"tag":108,"props":1705,"children":1706},{"style":489},[1707],{"type":28,"value":1708}," Image\n",{"type":23,"tag":108,"props":1710,"children":1711},{"class":110,"line":312},[1712,1716],{"type":23,"tag":108,"props":1713,"children":1714},{"style":483},[1715],{"type":28,"value":486},{"type":23,"tag":108,"props":1717,"children":1718},{"style":489},[1719],{"type":28,"value":1720}," pytesseract\n",{"type":23,"tag":108,"props":1722,"children":1723},{"class":110,"line":442},[1724,1728],{"type":23,"tag":108,"props":1725,"children":1726},{"style":483},[1727],{"type":28,"value":486},{"type":23,"tag":108,"props":1729,"children":1730},{"style":489},[1731],{"type":28,"value":1732}," argparse\n",{"type":23,"tag":108,"props":1734,"children":1735},{"class":110,"line":512},[1736,1740],{"type":23,"tag":108,"props":1737,"children":1738},{"style":483},[1739],{"type":28,"value":486},{"type":23,"tag":108,"props":1741,"children":1742},{"style":489},[1743],{"type":28,"value":1744}," sys\n",{"type":23,"tag":108,"props":1746,"children":1747},{"class":110,"line":551},[1748],{"type":23,"tag":108,"props":1749,"children":1750},{"emptyLinePlaceholder":497},[1751],{"type":28,"value":500},{"type":23,"tag":108,"props":1753,"children":1754},{"class":110,"line":578},[1755,1760,1764],{"type":23,"tag":108,"props":1756,"children":1757},{"style":489},[1758],{"type":28,"value":1759},"original_image ",{"type":23,"tag":108,"props":1761,"children":1762},{"style":483},[1763],{"type":28,"value":523},{"type":23,"tag":108,"props":1765,"children":1766},{"style":121},[1767],{"type":28,"value":1768}," \"image.jpg\"\n",{"type":23,"tag":108,"props":1770,"children":1771},{"class":110,"line":596},[1772,1777,1781],{"type":23,"tag":108,"props":1773,"children":1774},{"style":489},[1775],{"type":28,"value":1776},"image ",{"type":23,"tag":108,"props":1778,"children":1779},{"style":483},[1780],{"type":28,"value":523},{"type":23,"tag":108,"props":1782,"children":1783},{"style":489},[1784],{"type":28,"value":1785}," cv2.imread(original_image)\n",{"type":23,"tag":108,"props":1787,"children":1788},{"class":110,"line":604},[1789,1794,1798,1803,1808],{"type":23,"tag":108,"props":1790,"children":1791},{"style":489},[1792],{"type":28,"value":1793},"gray ",{"type":23,"tag":108,"props":1795,"children":1796},{"style":483},[1797],{"type":28,"value":523},{"type":23,"tag":108,"props":1799,"children":1800},{"style":489},[1801],{"type":28,"value":1802}," cv2.cvtColor(image, cv2.",{"type":23,"tag":108,"props":1804,"children":1805},{"style":127},[1806],{"type":28,"value":1807},"COLOR_BGR2GRAY",{"type":23,"tag":108,"props":1809,"children":1810},{"style":489},[1811],{"type":28,"value":548},{"type":23,"tag":108,"props":1813,"children":1814},{"class":110,"line":618},[1815],{"type":23,"tag":108,"props":1816,"children":1817},{"emptyLinePlaceholder":497},[1818],{"type":28,"value":500},{"type":23,"tag":108,"props":1820,"children":1821},{"class":110,"line":627},[1822],{"type":23,"tag":108,"props":1823,"children":1824},{"style":506},[1825],{"type":28,"value":1826},"# Convert to grayscale for better performance\n",{"type":23,"tag":108,"props":1828,"children":1829},{"class":110,"line":650},[1830,1835,1839],{"type":23,"tag":108,"props":1831,"children":1832},{"style":489},[1833],{"type":28,"value":1834},"filename ",{"type":23,"tag":108,"props":1836,"children":1837},{"style":483},[1838],{"type":28,"value":523},{"type":23,"tag":108,"props":1840,"children":1841},{"style":121},[1842],{"type":28,"value":1843}," \"grayscale_image.png\"\n",{"type":23,"tag":108,"props":1845,"children":1846},{"class":110,"line":663},[1847],{"type":23,"tag":108,"props":1848,"children":1849},{"style":489},[1850],{"type":28,"value":1851},"cv2.imwrite(filename, gray)\n",{"type":23,"tag":108,"props":1853,"children":1854},{"class":110,"line":1261},[1855],{"type":23,"tag":108,"props":1856,"children":1857},{"emptyLinePlaceholder":497},[1858],{"type":28,"value":500},{"type":23,"tag":108,"props":1860,"children":1861},{"class":110,"line":1281},[1862],{"type":23,"tag":108,"props":1863,"children":1864},{"style":506},[1865],{"type":28,"value":1866},"# Load the image as a PIL/Pillow image and apply OCR\n",{"type":23,"tag":108,"props":1868,"children":1869},{"class":110,"line":1289},[1870,1875,1879],{"type":23,"tag":108,"props":1871,"children":1872},{"style":489},[1873],{"type":28,"value":1874},"text ",{"type":23,"tag":108,"props":1876,"children":1877},{"style":483},[1878],{"type":28,"value":523},{"type":23,"tag":108,"props":1880,"children":1881},{"style":489},[1882],{"type":28,"value":1883}," pytesseract.image_to_string(Image.open(filename))\n",{"type":23,"tag":108,"props":1885,"children":1886},{"class":110,"line":1307},[1887],{"type":23,"tag":108,"props":1888,"children":1889},{"style":489},[1890],{"type":28,"value":1891},"os.remove(filename)\n",{"type":23,"tag":108,"props":1893,"children":1894},{"class":110,"line":1316},[1895,1899],{"type":23,"tag":108,"props":1896,"children":1897},{"style":127},[1898],{"type":28,"value":942},{"type":23,"tag":108,"props":1900,"children":1901},{"style":489},[1902],{"type":28,"value":1903},"(text)\n",{"type":23,"tag":24,"props":1905,"children":1906},{},[1907,1909],{"type":28,"value":1908},"You can find the complete code of this example in ",{"type":23,"tag":347,"props":1910,"children":1913},{"href":1911,"rel":1912},"https://github.com/JaimeDeArcos/ocr-python",[1461],[1914],{"type":28,"value":1915},"this GitHub repository",{"type":23,"tag":31,"props":1917,"children":1919},{"id":1918},"references",[1920],{"type":28,"value":1921},"References",{"type":23,"tag":43,"props":1923,"children":1924},{},[1925],{"type":23,"tag":47,"props":1926,"children":1927},{},[1928],{"type":23,"tag":347,"props":1929,"children":1931},{"href":1503,"rel":1930},[1461],[1932],{"type":28,"value":1933},"PyTesseract pip documentation",{"type":23,"tag":306,"props":1935,"children":1936},{},[1937],{"type":28,"value":310},{"title":8,"searchDepth":312,"depth":312,"links":1939},[1940,1941,1942],{"id":1511,"depth":312,"text":1514},{"id":1675,"depth":312,"text":1678},{"id":1918,"depth":312,"text":1921},"content:posts:playing-with-ocr-libraries.md","posts/playing-with-ocr-libraries.md","posts/playing-with-ocr-libraries",1790510064590]