I can't seem to import the email module at all. Every time I do it I get an error. I've tried uninstalling Python and reinstalling, but the email module just refuses to work. I've even done "pip install email" and it's still broken. I'm on Windows 7 Home Premium x64, running an x86 version of Python.
Here's what happens:
c:\Users\Nicholas\Desktop>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "email.py", line 1, in <module>
import smtplib
File "C:\Python27\lib\smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
>>>
EDIT: I've tried both Python from python.org and ActivePython, thinking ActivePython might work. Is there anyway to completely remove python and all its data and start 100% fresh maybe?
It looks like you have a file named email.py. Don't use file names that have the same name as Python standard library modules. Generally, your working directory comes earlier on the Python search path for importing modules so files in your working directory will override modules with the same name in the standard library.
The clue: note the path names in the traceback
File "email.py", line 1, in <module>
import smtplib
File "C:\Python27\lib\smtplib.py", line 46, in <module>
import email.utils
By the way, this is a very common error. The excellent tutorial in the Python standard documentation set talks about it here.
I just came across this error and wanted to share my solution. In my case, I had a file named email.py in directory. This created a name conflict between Python's email.py and my file. When smtplib tried to import email.utils it looked and my file and didn't find anything. After I renamed my copy of email.py into myemail.py everything worked like a charm.
I also came across this error. In addition to renaming the email.py to something else, you must also remove the email.pyc (notice the C) file. After that, all is well. Thanks all!
I also fetched this problem because i had a file named email.py in my project directory. I wasn't able to import urllib.request . When i changed the file name email.py to emailtest.py then the error gone away.
In every time we should not use the name what is same as python core file name.
If none of the posted solution works, try the following:
(Use the combo python3 / pip3 OR python / pip and try not to mix those)
Delete your current virtual environment directory.
Create new virtual environment and activate it with 'source'.
If exist, run the <pip install -r requirements.txt>.
Install any missing packages with pip or pip3.
Run the application to see if that solved the problem.
npm install email
has fix my problem, try it.
Related
I'm running Python 3.6.4, and am getting an import error from pandas. I'm installing it with 'pip install pandas' (which installs version 0.22). Installing it seems to go fine, but when I try to import it, an error gets thrown:
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\lib\site-packages\pandas\__init__.py", line 13, in <module>
__import__(dependency)
File "C:\Python36\lib\site-packages\pytz\__init__.py", line 32, in <module>
from pytz.lazy import LazyDict, LazyList, LazySet
File "C:\Python36\lib\site-packages\pytz\lazy.py", line 3, in <module>
from UserDict import DictMixin
File "C:\Python36\lib\UserDict.py", line 167
raise TypeError, "pop expected at most 2 arguments, got "\
Any help is much appreciated! Thank you!!
Edit:
Stephen pointed out that the root problem is pytz failing to import. Importing anything form pytz throws the same error. I've found one reference to the same error (http://www.smashcompany.com/technology/weird-that-under-python-3-4-runtime-you-can-import-from-2-7), which suggested an old path variable was the problem. I don't see any outdated python variables in my PATH, however.
Unless you use a virtual environment, pip usually corresponds to Python 2.x. The convention is to use pip3 to refer to the pip binary for Python 3.x. Since you are using 3.6.4, pip may be installing pandas for the wrong version of Python. You can confirm if it's using the correct one with
pip --version
If it says that it's using an interpreter other than the one you are using to run your code, try using
pip3 install pandas
instead.
I didn't figure out what caused the problem, but I was able to fix this by manually deleting all of the python files and directories still left behind after uninstalling python (not sure if it is normal that files were left at all) and then doing a completely fresh install.
There were no import problems after a 100% fresh install. Something must have gotten messed up, and running the default 'repair' or 'uninstall' and 'install' through the python installer (of multiple versions) wasn't correcting it.
i was trying to create an application with python using the moviepy library. I installed it using:
pip install moviepy
I found this from a MoviePy crash-course:
# Import everything needed to edit video clips
from moviepy.editor import *
After trying to run this line i get this error:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # Import everything needed to edit video clips
... from moviepy.editor import *
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "C:\Python27\lib\site-packages\moviepy\editor.py", line 22, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "C:\Python27\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "C:\Python27\lib\site-packages\moviepy\video\VideoClip.py", line 20, in <module>
from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 15, in <module>
from moviepy.config import get_setting
File "C:\Python27\lib\site-packages\moviepy\config.py", line 38, in <module>
FFMPEG_BINARY = get_exe()
File "C:\Python27\lib\site-packages\imageio\plugins\ffmpeg.py", line 86, in get_exe
raise NeedDownloadError('Need ffmpeg exe. '
imageio.core.fetching.NeedDownloadError: Need ffmpeg exe. You can download it by calling:
imageio.plugins.ffmpeg.download()
What is the problem here, and how can i fix it?
EDIT:
You can now update moviepy to v0.2.3.3 with pip install --upgrade moviepy and it will automatically install ffmpeg when required upon import of moviepy.editor (#731)
Run in a python console/shell (e.g. IPython/IDLE shell):
>>> import imageio
>>> imageio.plugins.ffmpeg.download()
Moviepy depends on the library imageio, which uses the program ffmpeg. It needs to download it before it can use it, and you can download it with the above imageio command.
I had a similar issue. It got fixed by the following line of code.
python -m pip install moviepy
I was having a similar issue; the ffmpeg plugin was downloaded automatically for me, but still couldn't import the editor. In my case, another dependency was missing: I fixed it by doing a
pip install --user requests
EXPLANATION:
(Context: not needed but maybe helpful for others) I needed the imagepy.editor in order to send some tensors as video to TensorBoard using the amazing tensorboardX project. Since I still had an import error, tbX kept telling me that I need imagepy, which I had. See the corresponding GitHub issue that I opened for more details.
Taking a closer look at the module via import imagepy; help(imagepy), I saw the editor submodule listed, which further confused me: trying to import it returned AttributeError: 'module' object has no attribute 'editor'
So the actual error had to be covered somewhere. I commented out the only line in the module's __init__ fle (which you can find via imagepy.__file__) and added an explicit import editor, which unleashed the error message: ImportError: No module named requests
At this point, installing the requests package and restoring the __init__file to its original state did the job. Hope this helps!
Cheers,
Andres
I encountered this issue today. When I installed MoviePy, every required component got installed as well ( I use pip ) but for some reason, I encountered that same issue. So, I literally tried everything that was mentioned above but still, nothing worked. The funny thing was that after investigated my /usr/bin/ I decided to switch from #!bin/python to #!/bin/python3 and I ended up getting error messages from pylint ( visual studio extension) - meaning it successfully imported moviepy.editor . But still, I was getting the same error so I decided to use python3 instead of python when executing my file.py and it worked.
so my solution: python3 your_file_that_contains_moviepy.py
I would also advise to alias pip3 as pip and python3 as python
If you're trying to do it on Jupyter (in VSCode) you should try %pip install moviepy, directly above the import command. Just like this:
%pip install moviepy
from moviepy.editor import *
We have multiple Python versions installed into a remote location. /remote/Python-2.7/bin/python or /remote/Python-2.7.2-shared/linux32/bin/python etc...... In the code, we use /remote/Python-2.7-shared. I need to use module which is installed in Python-2.7 (like numpy,matplotlib) but not shared location.
In the code we begin Python code like
#! /usr/bin/env py
is it possible to import module from different Python version.?
One suggestion, I got from Google search. We can change the python path at first line of your code.
#! /remote/Python-2.7/bin py
But it also does not have some package which installed in shared and required into code.
Could I have input to fix this issue.
I could not understand what is the reason for IT guys to installed multiple version of Python . I can raise ticket also which require lot of approval installing same package in shared location( or In short, no ticket for installing package)
Note. I have tried all option but seems nothing is working. Maybe I am doing mistake.
How to import a module given the full path?
Any input will help me lot.
I tried below suggestion But end up with following error. sys.path.inser(0,"path_location")
Traceback (most recent call last):
import numpy
File "/remote/Python-2.7.2/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/remote/Python-2.7.2/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/remote/Python-2.7.2/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/remote/Python-2.7.2/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/remote/Python-2.7.2/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /remote/Python-2.7.2/lib/python2.7/site-packages/numpy/core/multiarray.so: cannot open shared object file: No such file or directory
The "shebang" line is an opportunity for the script to tell *nix-ish OSes which script executable to use for running the script. If you wish to specify a particular installed version of the Python interpreter, this would be a good way to do it in your situation.
If you wish to import modules outside of your default path/PYTHONPATH, you can two options:
Modify your PYTHONPATH environment variable
in your script, import sys and modify your path like so:
import sys
sys.path.insert(0, "path_to_module")
This customizes script's path for the duration of the script and will allow any following imports to find the target file.
virtualenvs are the preferred option. But sometimes its about just getting the task accomplished.
It looks like you really need are Virtual Envs (Virtual Environments). They are the de facto way to have multiple Pythons installed in the same machine.
I recommend you to read this Wikipedia article about SheBang. It will help you to understand what is happening.
Your first line (the SheBang) should be the executable of the interpreter that you want to execute. Use the one that has the library you want installed. Don't let any spaces between the exclamation point and the command.
Try:
#!/remote/Python-2.7.2-shared/linux32/bin/python
or
#!/remote/Python-2.7/bin/python
You should be able to run in a shell the interpreter you want to use, and then import the module you want to use:
$ /remote/Python-2.7/bin/python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
If you can't run these commands in the console of your remote machine, you should change the interpreter you are using. Don't use #!/bin/env python, since it will use your user environment path to decide which python to use. You'll have more trouble to discover what is happening. Use directly the interpreter you want to run.
To keep it simple, don't use the #!
I installed wmi with the installer here http://timgolden.me.uk/python/wmi/index.html
but I can't get the module to import.
Here is my code:
import wmi
c=wmi.WMI()
for os in c.Win32_OperatingSystem():
print(os.Caption)
and here is the error:
Traceback (most recent call last):
File "C:/Python33/Programs/WMI trial.py", line 1, in <module>
import wmi
File "C:\Python33\lib\site-packages\wmi.py", line 88, in <module>
from win32com.client import GetObject, Dispatch
ImportError: No module named 'win32com'
Any idea why this isn't working? I have a 64 bit system but that hasn't affected running 32 bit python at all.
Any help is greatly appreciated!
you are missing the 'Python For Windows Extensions' (pywin32).
WMI module requires pywin32.
run the appropriate installer for pywin32, then try WMI again.
The "No module named 'win32com'" error is because it can't find the winm32com module (which is installed as part of pywin32 package.)
What worked for me is:
i downloaded the source named: WMI-1.4.9.zip from https://pypi.python.org/pypi/WMI/
Extracted all files from that zip file and saved it in a folder named: WMI-1.4.9 and then copied that folder to C:\Python27\Lib\site-packages.
After that I navigated to that folder C:\Python27\Lib\site-packages\WMI-1.4.9 and did a shift + right click -> Open Command line here and ran: python setup.py install
That's it, after that it worked for me like charm. No issues.
p.s - While installing exe I had some weird Access Denied errors, I tried by running the exe as Administrator even then I could get through it. Hence that didn't at all work for me.
Edit:
Also I had pywin32 installed from here:
http://sourceforge.net/projects/pywin32/files/ (select the correct file - 'bittedness' and python version wise)
I'm trying to add win32com to Python 2.7. After looking at this, I added the directory with the _init file (Python27\Lib\site-packages\win32com) but I still get it. I went so far as to try to add a bunch of different folders to the path that seem to have to deal with win32com but I still get the error. If it knows where the file is and I added that folder to PYTHONPATH, why is this happening? I'm using PyDev with Eclipse Juno. My code:
import win32com.client
print("hello world")
when I try to run this, i get this error
Traceback (most recent call last):
File "C:\Users\Daniel\EclipseWorkspace\PhotoScript\src\scriptLaunch.py", line 1, in <module>
import win32com.client
File "C:\Python27\Lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.
in my case typing in cmd:
python C:\Python27\Scripts\pywin32_postinstall.py -install
cmd Windows
I hope this helps
Try installing ActivePython, it includes win32com:
The Python for Windows Extensions (PyWin32 version 214).
The interface to the Win32 API (win32api).
The interfaces to Win32 COM (win32com and win32comext).
The Pythonwin Development Environment.
*ActivePython is fully binary compatible with python.org Python builds to ensure that 3rd-party binary extensions just work*
Try to install python for windows extensions:
https://sourceforge.net/projects/pywin32/files/pywin32/Build%20210/