Skip to content

Latest commit

 

History

History
145 lines (98 loc) · 5.82 KB

How_to_Raspberry.md

File metadata and controls

145 lines (98 loc) · 5.82 KB

Tutorial for Raspberry Pi3b: Install InstaPy with Python 3.7 and venv

Basic Raspbian Configuration

NOTE: If you add an empty file named ssh to the boot directory, ssh will be enabled when you first start your RPi (more info on the official website - section 3 - here). If you do this, you can connect your RPi via ethernet, ssh in (once you have your ip) and skip right to the update step below (step 7). If you do not want to do this, follow the initial setup instructions to connect peripherals below.

  1. connect rpi3 to monitor via HDMI
  2. connect internet via cat5
  3. insert usb for wireless keyboard and mouse (if using)
  4. plug in rpi3 with sd card installed with Raspbian Stretch with desktop
  5. select country & configure Raspbian
  6. open terminal --> sudo raspi-config -->interfacing options --> SSH -->enable (allows ssh connection from MacBook); then navigate to VNC --> enable (allows GUI access)
  7. sudo apt-get update && sudo apt-get upgrade

Python 3.7 install guide

If you installed the newest version of Raspian, skip to Install InstaPy

STEP 1: First install the dependencies needed to build.

  1. sudo apt-get update
  2. sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev

STEP 2: Compile (takes a while!)

  1. wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
  2. tar xf Python-3.7.0.tar.xz
  3. cd Python-3.7.0
  4. ./configure --prefix=/usr/local/opt/python-3.7.0
  5. make -j 4

STEP 3: Install

  1. sudo make altinstall

STEP 4: Make Python 3.7 the default version, make aliases

  1. sudo ln -s /usr/local/opt/python-3.7.0/bin/pydoc3.7 /usr/bin/pydoc3.7
  2. sudo ln -s /usr/local/opt/python-3.7.0/bin/python3.7 /usr/bin/python3.7
  3. sudo ln -s /usr/local/opt/python-3.7.0/bin/python3.7m /usr/bin/python3.7m
  4. sudo ln -s /usr/local/opt/python-3.7.0/bin/pyvenv-3.7 /usr/bin/pyvenv-3.7
  5. sudo ln -s /usr/local/opt/python-3.7.0/bin/pip3.7 /usr/bin/pip3.7
  6. alias python3='/usr/bin/python3.7'
  7. echo "alias python3='/usr/bin/python3.7'" >> ~/.bashrc

STEP 5: Remove install files

  1. cd ..
  2. sudo rm -r Python-3.7.0
  3. rm Python-3.7.0.tar.xz

Install InstaPy

  1. sudo apt-get update && sudo apt-get upgrade
  2. mkdir Projects
  3. cd Projects
  4. python3 -m venv /home/pi/Projects/venv37
  5. source venv37/bin/activate
  6. python3 -m pip install instapy -u

NOTE: the last step (6.) takes quite a while!

For Chrome

Navigate to the assets folder in your Workspace:

  1. cd InstaPy/assets <-- or wherever your workspace is (note: you may have to run python quickstart.py before)
  2. wget https://github.com/electron/electron/releases/download/v3.0.0-beta.5/chromedriver-v3.0.0-beta.5-linux-armv7l.zip
  3. unzip chromedriver-v3.0.0-beta.5-linux-armv7l.zip

NOTE: use headless_browser=True if you get an error running python quickstart.py!

For Firefox

Remove any versions of Firefox as it will conflict with the correct one installed below:

  1. sudo apt-get remove firefox-esr

  2. sudo apt-get remove iceweasel

  3. sudo apt-get remove firefox

  4. echo 'deb http://q4os.org/qextrepo q4os-rpi-firefox-cn main' | sudo tee /etc/apt/sources.list.d/qextrepo.list

  5. wget -nv -O- http://q4os.org/qextrepo/q4a-q4os.gpg.pub | sudo apt-key add -

  6. sudo apt-get update

  7. sudo apt-get install firefox

Update GeckoDriver if needed. Instructions at the end of this document.

Firefox is not currently working correctly on Pi 2, to install a working version the following commands should be used: Pi2.1. wget https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/10930950/+files/firefox_49.0+build4-0ubuntu0.14.04.1_armhf.deb

Pi2.2 sudo dpkg -i firefox_49.0+build4-0ubuntu0.14.04.1_armhf.deb

Finishing up the Firefox installation

Encountered some errors when trying to run the quickstart.py and ran the next 3 commands (all may not be necessary)

  1. sudo pip install future
  2. sudo apt-get install xvfb
  3. sudo pip install pyvirtualdisplay
  4. sudo reboot (may not be required, but no harm)

Assuming you've modified quickstart.py to your liking and added your Instagram login to instapy.py

  1. sudo xvfb-run python quickstart.py

I installed TMUX to help run this headless, so that I can disconnect from the session and have the program continue to run on the rpi3

  1. sudo apt-get install tmux (more info found here: https://github.com/tmux/tmux)
  2. If using firefox, follow the example seen in examples\firefoxExample.py to set the default browser as Firefox

How to update GeckoDriver on Raspbian

New releases can be found in: https://github.com/mozilla/geckodriver/releases

  1. wget https://github.com/mozilla/geckodriver/releases/download/v0.18.0/geckodriver-v0.18.0-arm7hf.tar.gz
  2. tar -xvzf geckodriver-v*
  3. chmod +x geckodriver
  4. sudo cp geckodriver /usr/local/bin/

Start script on boot

If you've installed globally you can start quickstart on boot

  1. sudo systemctl edit --force --full instapy.service
  2. Edit the file and save with:
Description=InstaPy
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
ExecStart=/usr/bin/python3 /home/pi/quickstart.py

[Install]
WantedBy=multi-user.target

Note: change ExecStart to wherever your quickstart.py is, and also note its specifying python3 here 3. systemctl enable instapy.service

You can check the most recent log lines with systemctl status instapy.service