I am currently well versed in java, but I am trying to get into python. I know the basics, but am struggling with package use and implementation into source code.
I have successfully installed both numpy and Pillow (or PIL):
Click here for cmd telling me both packages have been installed
When I typed import numpy into cmd running python, it worked no problem, but now I've tried to open IDLE and import it there, and written source code trying to import it and utalise parts of the numpy lib but it always gives me a ModuleNotFoundError
python idle shell import vs. cmd import
My folder layout is a little wacky:
C:
..Users
....B
......ForImagingProject
........PYTHON
..........(python standard subfolders)
..........Lib
............site-packages
..............numpy and PIL and pip here
Any and all help would be appreciated
Thanks ~ B
EDIT: I messed up and my IDLE shortcut was running idle.pyw instead of idle.bat. Everything working smoothly now.
Check your IDLE's python executable. Is it the same one as in your cmd prompt?
The easiest way to check is to run this:
import sys
print(sys.path)
Look for something like
'PATH_TO_PYTHON/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7'or
'PATH_TO_PYTHON/Frameworks/Python.framework/Versions/2.7/lib/python2.7'
Make sure this is the same in both the IDLE and in cmd.
The reason the shell I was working in was unable to recognize the module was because my IDLE shortcut was mapped to idle.pyw instead of idle.bat. Everything running smoothly now
Related
I tried to install EZGmail module for Python. When I check my interpreter settings, it shows it as installed in the PyCharm list. I then use this same interpreter for my project, but I get a module not found error when trying to import EZGmail. What should I check?
Looks like you're trying to import the module in a different casing than it's mentioned on the document.
You're trying to do:
import EZGmail
while the Quickstart document says:
import ezgmail
I am new in python and last month I have installed matplotlib module in my python and using that I have also done some codes successfully. But now suddenly I don't know why my matlpotlib module is not working. When I write "import matplotlib.pyplot as plt" it shows the error "ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package" and the codes that was done before are also not working and showing the same error."import matplotlib" statement works properly in command prompt and IDLE. What am I suppose to do to solve this problem?
Thanks to this github issue, I realise that I shouldn't try to reload tensorflow, because I get this error:
del python
NameError: name 'python' is not defined
when I do
import tensorflow
from deeplab import common
In case it's relevant, import deeplab works fine.
I saw elsewhere that it's probably the IPython session in spyder that is keeping a tensorflow session open. So I closed spyder - but launching python in the shell gave me the same issue. ps -ef | grep -E 'py|tensorflow|tensorboard|tf' came up empty. What could still be hanging around and causing tensorflow to try a reload, rather than a fresh load?
I understand that the issue around reloading tensorflow will not be resolved. How do I make sure that I have cleared everything from my previous runs so that it will be a fresh load rather than a reload?
Edit: even after restarting the computer I get the same error. Even if the first thing I do is open a python console and type from deeplab import common. That means the original title to my question is probably wrong, so I have changed it.
I tried to code on Pycharm, but when I use from keras import backend as K it throws an import error like "cannot import name backend". But I can do it on terminal.
How can I fix this?
error
on terminal
Are you sure your PyCharm sees the same Python environment as what you are using in Terminal?
See if this possibly works for you:
use tensorflow on pyCharm
I got the same problem:
Check here:Pycharm cannot find installed packages: keras
After adding new package to project interpreter, you need to quit Pycharm and restart it again.
Use
from tensorflow.python.keras import backend as K
instead.
I am trying to execute a python method from eclipse using jython. I managed to run it with following code:
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("Mypython.py");
interpreter.eval("MyClassName().MyMethodName()")
My problem is when I import another python script, which exists even in the same directory with Mypython.py. For example, when I add:
from food import Pizza
to Mypython.py, it starts to complain that cannot import. ImportError..
I found some questions about importing python libaries like os, but in my case this is not an issue.
I tried to make the folder as a package, add init.py etc but it failed. I saw some people use PySystemState, but I think it is for jython modules not user python scripts. if this is the solution please give me a simple example.
Could you please help me with that problem.
sys.path is your module-import search path. You can import sys and then modify sys.path as required.