5

I'm using anaconda on linux and I want to install smtplib to send mail. I have tried,

conda install smtplib which returned:

PackageNotFoundError: Package missing in current linux-64 channels: - smtplib , and,

pip install smtplib which returned:

Could not find a version that satisfies the requirement smtplib (from versions: ) No matching distribution found for smtplib

I found that smtplib comes by default in the standard python distribution and I wonder why it is not available in anaconda.

Question: How to install smtplib? Or more generically, how to install a package that is not included in anaconda?

There are similar questions here and here but without any answers.


Spec: Python 2.7.13 |Anaconda 4.3.1 (64-bit)| (default, Dec 20 2016, 23:09:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2

akilat90
  • 5,436
  • 7
  • 28
  • 42
  • 2
    Do you really need to install it? You can just import it without installation, it's a built-in library. – Sraw May 26 '17 at 10:26
  • @Sraw I can't understand why conda is not including that. `conda list | grep smtplib` returns nothing. – akilat90 May 26 '17 at 10:39
  • 1
    What I did is just `conda create python2.7 python=2.7` `source activate python2.7` `python` `>>import smtplib`. Then it works. Just import it pls. – Sraw May 26 '17 at 10:43
  • Thanks. I think the first command should be like `conda create -n python=2.7 anaconda`. Then it works. How should I tell my python script to use this newly created environment (specially if I'm running this with a cron job)? – akilat90 May 26 '17 at 11:15
  • Actually, `anaconda` is a collection of generally used packages, so it is not necessary. You can't just tell a script to run in an environment. You can only run a script in an environment. To do this, use `source activate ` to activate this environment, and then run your script by `python – Sraw May 26 '17 at 15:02
  • Thanks. Please provide this as an answer so that I can accept. – akilat90 May 26 '17 at 15:27

3 Answers3

11

First, the real environment manager is conda, and anaconda is actually a collection of generally used packages for scientific calculation, so it is not necessary for creating an environment.

Second, smtplib is a built-in package for both python2.7 and python3.x, so there is no need for installation. You can import it without installing any other package.

Finally, what source activate <venv name> really does is that modify your environment variables in the current console. That also means change the path of command python and pip and the path where the python program looks for installed modules. In a word, source activate <venv name> activate a separated environment for python.

Sraw
  • 18,892
  • 11
  • 54
  • 87
  • I still can't understand why did I get `ImportError: No module named smtplib` when tried to run the script in the default environment. – akilat90 May 27 '17 at 10:25
1

https://docs.python.org/3/library/smtplib.html

It's a part of the standard library, you should be able to import the smtplib module without installing anything. Anaconda comes with Python so smtplib technically does come with Anaconda if that makes sense.

ally-e
  • 1,515
  • 10
  • 13
0

Install smtplib in your system using command prompt and then you can use same via Anaconda

To know about how to install smtplib in windows visit https://stackoverflow.com/a/70484083/17385292

dataninsight
  • 1,069
  • 6
  • 13