简体   繁体   中英

ModuleNotFoundError for Execute Selection in Console (PyCharm)

I am just starting to tinker with Python with an eye towards data science. Trying to start using numpy. Using PyCharm Professional 2017.1.2 and CPython 3.6.1 on Windows 10.

I would like to run code in an "interactive" fashion, so I can execute single lines at a time and see their outputs without executing all the code. Also avoids having to print() everything..

Up until now, on the basic Python tutorials, this is working fine, I've been using the "Execute Selection In Console" (Alt + Shift + E) command on whatever code I want to run and tinker with.

However, I am now importing numpy for use in the next tutorial. The Alt + Shift + E thing seems to no longer work.

Example:

import numpy as np

x = np.array([1, 2, 3])

This works fine when I run the full project file ( [Shift + F10] or [Run Menu > Run File1])

However, highlighting the two lines of code and then using "Execute Selection In Console" (Alt + Shift + E), it returns this error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'numpy'

Any idea what is going on? How can I make use of packages and still run in an "interactive shell" in PyCharm?

Thanks!!

Are you sure you have numpy installed? If you go to File> Settings> Project:(project name)> Project Interpreter, you should see a list of installed packages. If you don't see numpy, you can click on the green plus button on the top right and search and install it.

Otherwise, It looks to me like you have the import on line 21, which should be placed at the top of your file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM