python-wechaty-puppet-itchat icon indicating copy to clipboard operation
python-wechaty-puppet-itchat copied to clipboard

Failed to start the example directly

Open zepengliu opened this issue 3 years ago • 14 comments

itchat运行example报错

Failed to start the example directly。 Prompt that the src library is missing But I Suspected it is a problem of source file path

zepengliu avatar Sep 27 '21 04:09 zepengliu

wrong way to import it show there is a wrong way to import itchat.

the code can't import from the src.

please check it out

zepengliu avatar Sep 27 '21 06:09 zepengliu

This is the basic python path problem, which is depended on the evironment you use. When you use pycharm as your development IDE, it will set the project root directory into your python path list where the python program will search package at. In your case, when you clone the project into 机器人 directory, the python program will not find the src module which is the problem you are facing.

So, there are some solutions:

  • open the python-wechaty-puppet-itchat-main directory with pycharm, so it will find the src module.
  • add the 机器人/python-wechaty-puppet-itchat-main directory into you sys.path.

Hope that can help you fix the problem.

wj-Mcat avatar Sep 27 '21 06:09 wj-Mcat

@lyleshaw I think we shoule not rename itchat, which is the source project name, to itchat_wechaty. There are some problems that itchat lies under src directory.

  • when you publish the wechaty-puppet-itchat package, it will package itchat and wechaty-puppet-itchat modules into one package. So, when we install the wechaty-puppet-itchat package, it will install itchat and wechaty_puppet_itchat modules into your site-packages. And what's more, it will exist itchat package before you install it, so it will get into conflict.
  • itchat shoule not be the external pacakge, because it has been heavily modified. In this situation, I suggest that we can move src/itchat directory into src/wechaty_puppet_itchat/ directory. So it will be the sub module of wechaty_puppet_itchat .

we should not import wechaty_puppet_itchat from src package, which is included in published pacakge. You can get publishing detail in setup.py.

wj-Mcat avatar Sep 27 '21 06:09 wj-Mcat

@zepengliu for your prblem, I think you can set the python-wechaty-puppet-itchat-main as the sources in your pycharm: Setting -> Project Structure -> Sources. Following this setting, the program will automaticly add it into your sys.path.

This is the small trick and tool of pycharm. Hope that can help you fix this issue.

wj-Mcat avatar Sep 27 '21 06:09 wj-Mcat

@lyleshaw I think we shoule not rename itchat, which is the source project name, to itchat_wechaty. There are some problems that itchat lies under src directory.

  • when you publish the wechaty-puppet-itchat package, it will package itchat and wechaty-puppet-itchat modules into one package. So, when we install the wechaty-puppet-itchat package, it will install itchat and wechaty_puppet_itchat modules into your site-packages. And what's more, it will exist itchat package before you install it, so it will get into conflict.
  • itchat shoule not be the external pacakge, because it has been heavily modified. In this situation, I suggest that we can move src/itchat directory into src/wechaty_puppet_itchat/ directory. So it will be the sub module of wechaty_puppet_itchat .

we should not import wechaty_puppet_itchat from src package, which is included in published pacakge. You can get publishing detail in setup.py.

Got it, I'll close that PR.

lyleshaw avatar Sep 27 '21 06:09 lyleshaw

A ha ~~~, you can contribute changes in this pr, because we have some discussions in this issue which is related to that pr. How do you think about @lyleshaw ?

wj-Mcat avatar Sep 27 '21 06:09 wj-Mcat

A ha ~~~, you can contribute changes in this pr, because we have some discussions in this issue which is related to that pr. How do you think about @lyleshaw ?

That's sounds great.

lyleshaw avatar Sep 27 '21 06:09 lyleshaw

anotherimport question first of all, through the method is success without the wrong to import src :Setting -> Project Structure -> Sources however,there is another wrong import .

zepengliu avatar Sep 27 '21 08:09 zepengliu

anotherimport question

first of all, through the method is success without the wrong to import src :Setting -> Project Structure -> Sources however,there is another wrong import . 同样的问题,ding可以收到,但是不回复dong。

fangjiyuan avatar Sep 27 '21 10:09 fangjiyuan

wrong import actually.you can see there is no site-pakage in the file of sqlalchemy.ext like asyncio.please check the code again..

zepengliu avatar Sep 27 '21 21:09 zepengliu

the correct result sorry,it is my problem. i should update sqlalchemy from 1.3.22 to 1.4.25 , it is ok now. I recommend you should write the sqlalchemy version in the requirement.txt also.

zepengliu avatar Sep 27 '21 21:09 zepengliu

the correct result

sorry,it is my problem. i should update sqlalchemy from 1.3.22 to 1.4.25 , it is ok now. I recommend you should write the sqlalchemy version in the requirement.txt also.

Got it.

I'll update requirement.txt in the next PR.

Thanks for your suggestion~

lyleshaw avatar Sep 28 '21 05:09 lyleshaw

因为pycharm和vscode等IDE工具的文件目录机制不同, 为了对入门用户更加友好,建议添加本文件夹路径和src路径。

import sys,os sys.path.append(os.getcwd()+"/src") sys.path.append(os.getcwd())

fangjiyuan avatar Sep 30 '21 03:09 fangjiyuan

因为pycharm和vscode等IDE工具的文件目录机制不同, 为了对入门用户更加友好,建议添加本文件夹路径和src路径。

import sys,os sys.path.append(os.getcwd()+"/src") sys.path.append(os.getcwd())

Thanks for your solution for this problem. But this is the very simple python path issue for developer which should not be here.

What's more, If you use the python-wechaty-puppet-itchat package, you will pip install wechaty-puppet-itchat not other than cloning the source code. So we should not add the src dir to python path variable list.

How do you think about it ? @fangjiyuan

wj-Mcat avatar Sep 30 '21 03:09 wj-Mcat