Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax errors
#1
Hi I am new to python, my reason for trying it is to backup the flash memory on my esp8266. I have installed python 3.6.2 and eventually esptools.py. being a newbie I rely on google to find the info I need. The first attempt to install esptool i used the code
$ pip install esptool
which didnt work came back with syntax error. Some more searching suggested
import pip
package_name-'esptool'
pip.main(['install', package_name])
which worked But if I then try
esptool -h
I get NameError esptool not defined. Further searching suggested I needed PySerial.py so I installed that too, but I am still getting syntax and not defined errors
this is the code to copy the memory
python.exe esptool.py --port COM5 --baud 115200 read_flash 0x000 524288 backup.bin
which returns SyntaxError: invalid syntax

Any help would be great, I imagine its something simple that I am not doing right

Screen shot
Reply
#2
I saw your screenshot, you are using esptool -h in Python interpreter which won't work, for using it in python use import esptool. This esptool -h command is for cmd.
Output:
C:\WINDOWS\system32>esptool -h usage: esptool [-h] [--chip {auto,esp8266,esp32}] [--port PORT] [--baud BAUD] [--before {default_reset,no_reset}] [--after {hard_reset,soft_reset,no_reset}] [--no-stub] {load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_id,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,version} ... esptool.py v2.0.1 - ESP8266 ROM Bootloader Utility positional arguments: {load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_id,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,version} Run esptool {command} -h for additional help load_ram Download an image to RAM and execute dump_mem Dump arbitrary memory to disk read_mem Read arbitrary memory location write_mem Read-modify-write to arbitrary memory location write_flash Write a binary blob to flash run Run application code in flash image_info Dump headers from an application image make_image Create an application image from binary files elf2image Create an application image from ELF file read_mac Read MAC address from OTP ROM chip_id Read Chip ID from OTP ROM flash_id Read SPI flash manufacturer and device ID read_flash_status Read SPI flash status register write_flash_status Write SPI flash status register read_flash Read SPI flash content verify_flash Verify a binary blob against flash erase_flash Perform Chip Erase on SPI flash erase_region Erase a region of the flash version Print esptool version optional arguments: -h, --help show this help message and exit --chip {auto,esp8266,esp32}, -c {auto,esp8266,esp32} Target chip type --port PORT, -p PORT Serial port device --baud BAUD, -b BAUD Serial port baud rate used when flashing/reading --before {default_reset,no_reset} What to do before connecting to the chip --after {hard_reset,soft_reset,no_reset}, -a {hard_reset,soft_reset,no_reset} What to do after esptool.py is finished --no-stub Disable launching the flasher stub, only talk to ROM bootloader. Some features will not be available.
Reply
#3
Hi thanks I tried what you said I think but still get stuck at esptool -h
https://drive.google.com/open?id=0B1Dk0B...WpqR2xBWjg
Reply
#4
Ok, so you may not have esptool installed.
Make sure you have pip check by pip --version.
Since pip install esptool didn't work for you. Try downloading it from LINK, extract it and then install via setup.py.
python setup.py install.

This should install it correctly.
BTW can you post the error you get when using pip install esptool
Reply
#5
Hmm still nothing, do I have to tell windows what esptool is? I think I read something about windows sometime not recognising python in the cmd and something needed to be done in windows settings?
https://drive.google.com/open?id=0B1Dk0B...mFjb2x4ems

thanks
Reply
#6
(Aug-20-2017, 07:18 AM)jon65 Wrote: something needed to be done in windows settings?
You need to add the python36\Scripts folder path to environment variable.
Reply
#7
pretty sure thats already done
https://drive.google.com/open?id=0B1Dk0B...DJ1ZWY3ZFE

https://drive.google.com/open?id=0B1Dk0B...El4dDhWamM
Reply
#8
So you have \python\scripts in user variables but if you open cmd as admin the user variables won't work.
You can add scripts to system variable path.
alternatively, you can use the complete path to esptool.
eg-
\python\scripts\esptool -h
Reply
#9
hi again, still no luck so I reinstalled python in c:/program files and did the pip install esptool successfully but still no good, this time I used windows powershell administrator, see image
https://drive.google.com/open?id=0B1Dk0B...2s5d3UyMlk
Reply
#10
(Aug-20-2017, 09:42 AM)jon65 Wrote: this time I used windows powershell administrator.

(Aug-20-2017, 08:15 AM)hbknjr Wrote: if you open cmd as admin the user variables won't work.
You misread it.

Troubleshoot with following steps.
1- Check is esptool is accessible with \fullpath\to\python\scripts\esptool -h.
2- open cmd(without admin) and try esptool -h. Make sure the path variable has script folder.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax errors: Struggling to setup enviroment and load packages AH56 5 2,800 Jun-30-2021, 01:01 PM
Last Post: AH56
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 4,464 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Mysterious syntax errors... help? friendlymegalomaniac 3 3,009 Apr-26-2018, 09:22 PM
Last Post: micseydel
  random syntax errors s4lty_b0i 3 3,209 Nov-26-2017, 03:45 PM
Last Post: heiner55
  y syntax errors? Saxycool12345 3 3,597 Sep-16-2017, 01:24 PM
Last Post: sparkz_alot
  Decorator toy code throws syntax errors kevinxhi 3 3,587 Sep-04-2017, 03:01 AM
Last Post: kevinxhi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020