How to install steem-python, the official STEEM library for Python

in utopian-io •  7 years ago  (edited)

In this post I will show you how to install steem-python, the official STEEM library for Python! I've mainly written this post as I spent a lot of time trying to install steem-python using other tutorials, but it was never as straightforward as they made it seem. Especially trying to install it on Windows is a complete hassle, as I will explain below.

Step 1 - Installing Ubuntu 16.04

Unfortunately installing steem-python on Windows is incredibly hard because it requires Python 3.6. The problem with this is that steem-python requires another package called scrypt, and this package is only available in a pre-compiled form for Windows when using Python 3.5 or below. This means that scrypt is near impossible to install on Windows when using Python 3.6, but don't worry, there is a solution to this problem! You can either download a virtual machine like VMware and install Ubuntu 16.04 on it (like I have done for the sake of this tutorial) or purchase one of the many available Ubuntu servers out there, like DigitalOcean's droplet. There are plenty of tutorials online on how to install Ubuntu on a virtual machine, or how to get an Ubuntu server up and running, so I won't be going over that here.

Step 2 - Installing Python 3.6

Ubuntu 16.04 comes with Python 2.7 and Python 3.5 already installed, but not with Python 3.6. There are multiple ways of installing Python 3.6, but in my opinion a very convenient way is by installing Anaconda. To do this you must do the following:

  1. Open a terminal with CTRL + ALT + T and navigate to the /tmp folder
    $ cd /tmp
  2. Find the latest version of Anaconda on their download page and use curl (install curl with sudo apt-get install curl if needed) to download it
    $ curl -O https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
  3. Once it is downloaded run the script (just keep pressing ENTER and type yes) to install Anaconda (this could take a while)
    $ bash Anaconda3-5.0.1-Linux-x86_64.sh
    Once it has finished installing it will ask the following:
    Do you wish the installer to prepend the Anaconda3 install location to PATH in your /home/amos/.bashrc ? [yes|no]
    Make sure you type yes, this makes it possible to use the conda command to see if Anaconda was installed correctly
  4. Source your ~/.bashrc file and make sure Anaconda was installed correctly
    $ source ~/.bashrc
    $ conda --version
    If this shows the version then it was installed correctly, otherwise follow step 5.
  5. (Optional) if you didn't add the Anaconda3 install location to PATH in step 3, or something else went wrong, then do the following:
    $ nano ~/.bashrc
    then add export PATH="/home/user/anaconda3/bin:$PATH" (where user is your username) to the end of the file, press ^X (CTRL + X) to save the changes and source ~./bashrc again.

Congratulations, typing python --version should now show Python 3.6.3 :: Anaconda, Inc!

Step 3 - Installing steem-python

  1. Before we install steem-python we need to first install an Ubuntu package that is needed by the Python package scrypt
    $ sudo apt-get install libssl-dev
  2. Once this is installed you can simply install steem-python using pip
    $ pip install -U steem
  3. Type python in your terminal to enter the Python interpreter and see if steem-python was installed correctly by doing the following

If you see something like the above image then you have installed steem-python correctly!

Step 4 - Fixing steempy CLI

If you try and import your account via the steempy CLI for example, you will see the following error:

Thankfully this is an easy fix. We simply need to edit steem-python's METADATA file and change the following line
Requires-Dist: toml (==0.9.3.1)
to
Requires-Dist: toml (==0.9.3)

You can open the METADATA file in an editor with the following command
$ nano /home/user/anaconda3/lib/python3.6/site-packages/steem-0.18.103.dist-info/METADATA
where user is once again your username.

Once you have changed that line everything should be working! Congratulations! When you try to import your account now you should see the following:

Step 5 - Create!

Now you've installed steem-python correctly, the next step is creating any program you want! An example of code I could've used to post this post on steemit (inception) can be seen below:

Read more about the library here!



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  7 years ago (edited)

Well you should change your tutorial, right now if you follow it you get an error as https://steemd.steemit.com does not exist anymore, now it must be changed to https://api.steemit.com, here is a screen capture of how to do it easily, editing the file "steemd.py" in the same directory where the CLI from step 4 is.
arreglar steempython.JPG
Afterwards it works ok and you don't need to specify the correct node.

It seems that it's already been fixed. I downloaded the package in the past few days and I just checked the file; It's already https://api.steemit.com.

  ·  7 years ago (edited)

Well I did this just three days ago and it was not fixed, maybe the steem python library version in the tutorial is not the last one and I did download that one.

Fair enough, maybe they only just updated it a day or two ago and you were unlucky enough to have downloaded it three days ago. Haha

it is really amazing. May I ask After we go through all the tutorials what we can do on steemit? Any interesting things we can achieve?

This is really cool and informative, but I believe Ubuntu does come with Python 3.6.3 now. I didnt have to deal with any Python updates on my fresh instalation (about a week ago) and my Python runs on 3.6.3.

Thanks for your contribution!

The latest LTS version of Ubuntu (16.04) doesn't come with Python 3.6 (I installed it today and tested everything on a virtual machine). The actual latest verson of Ubuntu (17.10), of which the download is currently discouraged, does come with Python 3.6, but it isn't the LTS version, so when getting a server (like a droplet) you will more than likely have Ubuntu 16.04 installed.

I see, I do work on 17.10 which explains a lot. Didn't even know steem API was such a pain in the ass, this tutorial is even more needed than I thought! Great work!

Hey @amosbastian I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Anyone using steem-python over Tor? Connecting over Tor with python is easy, figured I'd see if anyone has been doing so with steem-python.
Looking quickly at the code it seems that the code to change may be in HttpClient either in /steembase/ or HttpClient in /dist/steam-1.0.2....

Loading...

Hi, amosbastian.

Excellent Tutorial ..! I'm following it step by step.
I have a problem in Step 3.3 when I run the s.get_account ('rcuriel') instruction python enters a loop showing the following message ....

WARNING:urllib3.connectionpool:Retrying (Retry(total=19, connect=None, read=None, redirect=0, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb665594c>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /

...then I break it with Ctrl+"C"

Important, my operating system is Ubuntu Bionic Beaver (development branch)

could you help me..?

Hey, if you want you can contact me on Discord at Amos#4622, will be easier to help you out that way!

Hello again.
Try to communicate with you via Discord I did not know how to do it, I'm a novice.
looking on the internet I found this solution ...

steempy set nodes https://api.steemit.com

and it worked.

Your contribution cannot be approved because it does not follow the Utopian Rules, and is considered as plagiarism. Plagiarism is not allowed on Utopian, and posts that engage in plagiarism will be flagged and hidden forever.

You have copy pasted from here. https://github.com/amosbastian/steem-python-tutorial

You can contact us on Discord.
[utopian-moderator]

Thank you for the contribution. It has been approved.

apologies for the earlier. :)

You can contact us on Discord.
[utopian-moderator]

Hi, thanks for this tutorial! But I have some issues; I followed the tutorial step by step (digital ocean Ubuntu 16 droplet using the newest Anaconda3-5.1.0), but I always get error messages during the installation:

Failed building wheel for ujson
Failed building wheel for scrypt
Command "/home/myuser/anaconda3/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-tmqoph2t/ujson/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-8ssz9qmi-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-tmqoph2t/ujson/

Thanks for your help!

Hey! It would be easier for me to help out via Discord or something, so if you are still in need of help don't hesitate to contact me at Amos#4622!

Cool, thanks! I will write you when I get home today

@amosbastian thanks for the guide, couldn't have done it without you. Maybe you could help people on steemit instead of discord, would kill 2 birds with one stone! lol Then others could see what the error and solution is?? I posted how I got mine to work in case someone else runs into my same error. Is is there a newer updated steempy I can pip install?? In the future maybe you should ask each person to post their error and then you post the solution. In the long run if devs do more of that it will drive them to steemit and then your coins will go up too!

Just because it is easier to help people on discord does not mean it is better for us or STEEM!

YOU ARE A LIFESAVER! i've tried installing on windows 10 for over 8 hours and i failed.

there was a problem with connection tho, so i did this.
nodes=['https://api.steemit.com']
from steem import Steem
s = Steem(nodes)

anyways you're amazing 👍
i cant tell you how happy i am!

Well, now I have the same problem, but with step 4. I try
steempy importaccount gregario
asks for password, and then a long chain of error messages like the ones a had before. But now the fix
nodes=['https://api.steemit.com']
does not seem to apply, since here we are sending linux commands, while this is a python command.

I would very much appreciate any suggestions or comments.

Thanks again for these great insights.

Exactly what I needed! Thanks @amosbastian for the great, great instructions. And thanks to @roundbeargames for this clever fix.

'$ sudo apt-get install libssl-dev'

This literrally saved my life.

Haha, great!

I do not understand this at all ..

What can I help you with?

Help me to grow faster

Loading...