Python Forum

Full Version: Syntax errors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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
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.
Hi thanks I tried what you said I think but still get stuck at esptool -h
https://drive.google.com/open?id=0B1Dk0B...WpqR2xBWjg
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
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
(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.
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
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
(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.
Pages: 1 2 3