4

This is what i get when i do "python -V"

Python 2.7.11 :: Anaconda 2.4.0 (64-bit) I usually use my terminal to play with IDLE.But now i have also installed IDLE shell.

I tried import sys;sys.path on both.They throw different paths. My Terminal returned the path with anaconda in it.

I tried to install a module following these steps.

  1. python setup.py sdist

  2. sudo python setup.py install

Then i opened IDLE(shell).I was able to import and also use my module.

I wanna do the same in Anaconda..I tried using conda install filename.py.It doesn't work. Please help.

sanjith kumar
  • 325
  • 2
  • 3
  • 13

2 Answers2

6

There are several ways to add a module to Anaconda.

  • conda install <package>

  • pip install <package>

  • python setup.py install (if you are in the source directory, no sudo required if anaconda is in your home directory)

To make a package for others to use you will need to put it up where people can access it like Github. You will have to make a config file (takes yaml file manipulation) you can read up on how to make/distribute packages here. http://conda.pydata.org/docs/build_tutorials/pkgs.html

Now to answer your question: There is a difference between using a file and using a module/package. A file can just be imported in another python program using import filename where filename.py is the name of the file you want to use. to make that a module you want to take a look at the answer to this question. How to write a Python module?

Community
  • 1
  • 1
Back2Basics
  • 7,406
  • 2
  • 32
  • 45
  • 1
    Thanks man!.python setup.py install worked.Why is it lik that?how does sudo make a diff like that.I am a beginner.Thanks anyways. – sanjith kumar Feb 17 '16 at 04:02
  • Anaconda is installed in your home directory. You have the ability to add/change things in your home directory all you want. Sudo is a command to run programs as someone else, like the root user. – Back2Basics Feb 17 '16 at 07:27
1

I agree with the answer above. But just be careful when using: pip install Apparently a deprecated pip could generate problems like "Could not find a version that satisfies the requirement" So just to be on the safe side update your version.

That was my case. After looking at this link: https://pypi.org/project/opencv-python/

It said:

A: Most likely the issue is related to too old pip and can be fixed by running
pip install --upgrade pip.

So I decided to try updating mine. And it worked...
Hope this was helpful!

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
user
  • 93
  • 10
  • Hi, after I updated the version of pip, the problem disappeared. I believe in the link I put there was a comment on how the version of pip could create some problems. This was the case for me anyway. – user Jul 01 '19 at 11:23
  • Please [edit] your post to make it more obviously an answer to the question by adding the information from your link. – Yunnosch Jul 07 '19 at 06:23
  • Did you look at your post after editing it? Frankly it does not seem so. Please try for more readability in the future. This might help with that. https://stackoverflow.com/editing-help Also, please take the [tour]. – Yunnosch Jul 08 '19 at 16:01
  • It does however seem a decent answer now. (I just cannot verify, for lack of knowledge on my side. So please understand that I cannot upvote.) – Yunnosch Jul 08 '19 at 16:05