添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
豪情万千的小熊猫  ·  android ...·  3 月前    · 
腹黑的篮球  ·  sqlserver ...·  3 月前    · 
豪爽的麻辣香锅  ·  给我一段 ...·  6 月前    · 

I am an undergraduate student in computer science.Currently i am working on scikit-image.i am trying to run active_contour_model.py.I would like to ask you how can i fix this error.(Traceback (most recent call last):
File “/home/xarisis/PycharmProjects/scikit-image/skimage/segmentation/active_contour_model.py”, line 11, in
from …util import img_as_float
ValueError: attempted relative import beyond top-level package)

.I am using pycharm with python 3.7 on ubuntu 19.04 also using the latest scikit image version.Thanks in advance.

How have you installed everything? Through Anaconda? I’ve had issues in the past where Anaconda environments aren’t set up correctly and use the wrong Python or package version. I’m also not entirely sure how pycharm interacts with that but other editors have been known to use other paths also.

Can you copy the entire error, including traceback for people to see?

not through anaconda.Yes of course i can.—>traceback (most recent call last):
File “/home/xarisis/PycharmProjects/scikit-image/skimage/segmentation/active_contour_model.py”, line 11, in
from …util import img_as_float
ValueError: attempted relative import beyond top-level package

Thank your for the brief reply Nelson

So… you appear to be working from inside a copy of scikit-image. Is there a reason for this?

I would normally expect you to have install scikit-image into your environment/path/etc. and then your own files to be elsewhere, e.g. a git repo. Then you wouldn’t be importing from a folder that’s a directory higher than your file (which I believe is what the issue is about).

Two solutions that come to mind. One, don’t work from inside scikit-image (unless your trying to directly modify the module). Two, use sys.addpath but add the absolute path not the relative path (which it looks like you’ve tried).

Do either of those help?

Okay then, so in that case, have you installed in developer mode?:
https://packaging.python.org/tutorials/installing-packages/#installing-from-a-local-src-tree

Try that first but if it doesn’t work you can use the sys.path.insert function to add the path to the file you’re trying to import. But instead of using .. use \home\xarisis\PyCharmProjects\scikit-image … although now I write that out it sounds like a very bad way to solve this problem!

So the pip -e and path things are two different solutions.

To do the pip -e version you should set your environment up as usual, navigate (in the terminal) to your downloaded scikit-image folder and use pip -e install . (where the . means ‘this folder’); actually this seems to be detailed on scikit-image’s github page and in their install.RST file ( https://github.com/scikit-image/scikit-image ). Then, before making any changes confirm that scikit-image works using some of their examples and such.

Then, you should be able to make edits to the function as you wish.

Screenshot%20from%202019-11-13%2022-14-11 1920×1080 307 KB so now i can modify the code chas?

Edit:it keep throwing the same error

Well that seems to imply something else is wrong, if their own un-edited codes aren’t working.
Erm, and without knowing how you’re systems been set-up I’m a little at a loss…

Honestly, might be worth uninstalling every version of scikit image (see https://github.com/scikit-image/scikit-image/blob/master/INSTALL.rst ) and making sure it’s completely gone from your system. Then set-up a new environment and follow the development instructions.

After that, no idea sorry.

I think the issue here is the way you’re trying to run the file from the command line. I can’t see from your images but does that file you’re calling on the command line have a __main__ section?

Have you tried running it as a module ?
Briefly, this would look like
python -m path.to.file