kflash.py icon indicating copy to clipboard operation
kflash.py copied to clipboard

如何在window使用kflash

Open Reihold-Chen opened this issue 4 years ago • 9 comments

我是新手, 我正打算用kflash在window上烧录代码

我尝试过如下方法

  • kflash -B dan hello_world.bin : 无法将“kflash”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。
  • python kflash -B dan hello_world.bin : can't open file 'S:\kendryte-standalone-sdk-0.5.6\src\hello_world\build\kflash.py': [Errno 2] No such file or directory 这些方法都不管用, 我想应该是我的使用方法除了问题

我想我已经正常安装了kflash软件

pip list
Package            Version  
------------------ ---------
backports.tempfile 1.0      
backports.weakref  1.0.post1
enum34             1.1.10   
kflash             1.0.2    
pip                21.3     
pyelftools         0.27     
pyserial           3.5      
setuptools         56.0.0   

非常需要大家的帮助, 不胜感激!!

Reihold-Chen avatar Oct 13 '21 14:10 Reihold-Chen

你现在应该把安装kflash.py后的kflash文件所在的目录添加到Path中.

如果你使用conda管理python环境,pip安装后他会自动把可执行的python脚本放到conda的bin下面,不需要手动指定. 例如:

❯ which kflash
/Users/lisa/mambaforge/bin/kflash

zhen8838 avatar Oct 14 '21 02:10 zhen8838

试试这个:
python -m kflash -B dan hello_world.bin

或者:
python -m kflash/kflash -B dan hello_world.bin

GongT avatar Oct 14 '21 06:10 GongT

试试这个: python -m kflash -B dan hello_world.bin

或者: python -m kflash/kflash -B dan hello_world.bin @GongT 谢谢, 这个方法是可行的 python -m kflash -B dan hello_world.bin ·python -m kflash/kflash -B dan hello_world.bin· : 这个方法提示·C:\Python39\python.exe: No module named kflash/kflash·

Reihold-Chen avatar Oct 14 '21 07:10 Reihold-Chen

@zhen8838 在我的理解中, 添加环境变量PATH是把一个可执行文件的路径添加到这个变量中,这样shell在运行时会到PATH所在的目录搜索这些可执行文件。当kflash在我的理解中只是一个python脚本模块,他也能直接被终端运行吗?

我做了以下尝试:

参考了下列文章: https://frostming.com/2019/03-13/where-do-your-packages-go/ https://sysin.org/blog/windows-env/ 在powershell下运行

PS C:\Users\Edison> python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'C:\\Python39\\python.exe'
>>> sys.path
['', 'C:\\Python39\\python39.zip', 'C:\\Python39\\DLLs', 'C:\\Python39\\lib', 'C:\\Python39', 'C:\\Users\\Edison\\AppData\\Roaming\\Python\\Python39\\site-packages', 'C:\\Python39\\lib\\site-packages']
>>> sys.prefix
'C:\\Python39'
>>> import kflash
>>> kflash .__file__
'C:\\Python39\\lib\\site-packages\\kflash.py'

PS C:\Users\Edison> set path=%path%;"C:\\Users\\Edison\\AppData\\Roaming\\Python\\Python39\\site-packages"
C:\\Users\\Edison\\AppData\\Roaming\\Python\\Python39\\site-packages

在上面设置后, 执行 kflash -B dan hello_world.bin

kflash : 无法将“kflash”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径
正确,然后再试一次。
所在位置 行:1 字符: 1
+ kflash -B dan hello_world.bin
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (kflash:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Reihold-Chen avatar Oct 14 '21 08:10 Reihold-Chen

可执行的就是脚本, 默认会给你装一个kflash的脚本, 这个脚本包装了kflash的实现. 截屏2021-10-14 17 17 12

zhen8838 avatar Oct 14 '21 09:10 zhen8838

@zhen8838 可能是我的意思没表达到位.
应该这么理解吧, 脚本的运行还需要解释器的解释. 如果需要用到python的脚本, 需要这么写python -m kflash -B dan hello_world.bin , 指定用python解释器运行. 而不是kflash -B dan hello_world.bin , 这样写默认用shell的解释器运行. shell有自己的解释器, 他默认执行的脚本只能是shell语言的脚本.

Reihold-Chen avatar Oct 14 '21 09:10 Reihold-Chen

嗯 那应该是windows不能识别第一行注释。

zhen8838 avatar Oct 14 '21 09:10 zhen8838

你们解决了么

viys avatar Jul 12 '23 16:07 viys

image 我使用powershell无法进行烧录

viys avatar Jul 12 '23 16:07 viys