0

Python has package named ast, I want to import it, but I also have same name called ast, pycharm also show me local ast reference.

From docs

python3 use absolute import, so

import ast

should import python standard library

How to import python standard lib without renaming my ast file?

I am using Python 3.7

enter image description here

nuclear
  • 3,181
  • 3
  • 19
  • 38
  • Absolute imports have nothing to do with stdlib vs third-party modules, despite what some poorly-worded tutorials may say. Absolute imports just mean `import ast` always tries to import the `ast` module instead of `currentpackage.ast` (and no, `venv` is not a package and should not be a package). – user2357112 May 07 '19 at 07:23
  • Pick a different name. – user2357112 May 07 '19 at 07:24
  • Is eventloop a package, or just a folder containing the top-level files of your application? In the former case, it should have a __init__.py file, and then 'import ast' should not resolve to your file anymore (that would be 'import eventloop.ast'). In the latter case, well, you are creating a name clash between the standard library and your project, and I see no solution to your problem. – Pierre-Antoine May 07 '19 at 07:28
  • @Pierre-Antoine just a folder – nuclear May 07 '19 at 07:29
  • FTR, I do not consider this question to be a duplicate of https://stackoverflow.com/questions/1224741/trying-to-import-module-with-the-same-name-as-a-built-in-module-causes-an-import . They are of course related, but absolute import are the solution to the previous question; not to that one... – Pierre-Antoine May 08 '19 at 11:03
  • I suggest you make 'eventloop' a package. That would allow you to keep the file hierarchy as is, without renaming your files. That would require only minor change to your python files: replacing `import ast` by `import .ast` or `import eventloop.ast`. And you would get rid of the name clash. – Pierre-Antoine May 08 '19 at 11:06

0 Answers0