1

I need to install mpl_finance under a conda virtual environment, this package is not available via conda, only pip can install. I have tried below, does not work out, please advice.

I first set up a virtual env called cs231p under user/miniconda3/envs/cs231p. I cd to user/miniconda3/envs/cs231p/bin, and activated the env

conda activate cs231p

Then I do: conda list to make sure pip is there:

    ca-certificates           2019.1.23                     0  
    certifi                   2019.3.9                 py37_0  
    libcxx                    4.0.1                hcfea43d_1  
    libcxxabi                 4.0.1                hcfea43d_1  
    libedit                   3.1.20181209         hb402a30_0  
    libffi                    3.2.1                h475c297_4  
    ncurses                   6.1                  h0a44026_1  
    openssl                   1.1.1b               h1de35cc_1  
    pip                       19.0.3                   py37_0  

Then I do:

which pip

shows

 /miniconda3/envs/cs231p/bin/pip

(cs231p) bin$ pip install mpl_finance

I got error: but the path of pip is not from the virtual env that I set up.

XXX/anaconda/bin/python3.5: can't open file 'install': [Errno 2] No such file or directory

python -m pip install mpl_finance

gives

requirement already satisfied:mpl_finance in ~/anaconda/lib/python3.5/site-packages (0.10.0)

Lisa
  • 4,126
  • 12
  • 42
  • 71
  • instead of `pip install ...` you can also use `python -m pip install ....` – furas Apr 12 '19 at 05:09
  • 1
    I'd be curious the know the output of `which pip` (in the activated env) – cosmic_inquiry Apr 12 '19 at 06:22
  • updated in my question @furas – Lisa Apr 13 '19 at 18:07
  • updated in my question @cosmic_inquiry – Lisa Apr 13 '19 at 18:07
  • 1
    always show full Traceback, not only last line. You run `pip install` and you get `python3.5 can't open file install` - it looks like your `pip` is not real `pip` but alias for `python3.5`. Run `python3.5 install mpl_finance` and you get the same error. Maybe you have own local script/file with name `pip` and when you run it then it uses this script instead of expected `pip`. You can always try full path `/miniconda3/envs/cs231p/bin/pip install mpl_finance`. You can also create new environment to test if it is only problem with this one environment. – furas Apr 13 '19 at 19:26
  • @furas thanks it works! If you'd like to put your help into answer I will accept it. – Lisa Apr 14 '19 at 19:10
  • Not sure if conda has any specific option, but there's [python - How to install a package inside virtualenv? - Stack Overflow](https://stackoverflow.com/questions/21240653/how-to-install-a-package-inside-virtualenv) . – user202729 Jan 17 '21 at 16:49

2 Answers2

2

Instead of pip install ... you can also use python -m pip install ....

But you run pip install and you get python3.5 can't open file "install" - it looks like your pip is not real pip but alias for python3.5.

Run python3.5 install mpl_finance and you get the same error.

Maybe you have own local script/file with name pip and when you run it then it uses this script instead of expected pip.

You can always try full path /miniconda3/envs/cs231p/bin/pip install mpl_finance.

You can also create new environment to test if it is only problem with this one environment.

furas
  • 134,197
  • 12
  • 106
  • 148
  • how can i remove the mapping between "pip" command to python3.5 per your comments? i think this the trouble maker. Thx! @furas – Lisa Jun 22 '20 at 01:39
  • I don't know - I never met this problem before. Firts you would have to find current `pip` - ie using `which pip` and remove it or rename it. And maybe later it will work correctly if it can find correct `pip` - or you would have to copy correct `pip` in place/folder where was wrong `pip` (or create soft link - something like `ln -s /path/to/correct/pip /path/to/previous/wrong/pip` – furas Jun 22 '20 at 04:34
1
  1. activate anaconda virtual environment

    conda activate <env name>
    
  2. install the package using pip

    python -m pip install <package>
    
  3. deactivate conda virtual env

    conda deactivate
    
sahasrara62
  • 10,069
  • 3
  • 29
  • 44
  • The original version of the answer was exactly the same steps that the OP followed. I retracted the vote after the edit. – darthbith Apr 13 '19 at 13:54
  • I tried but it does not work out, Python -m seems install to anaconda's package instead of the virtual environment, please see details in my updated question. – Lisa Apr 13 '19 at 18:09
  • @Lisa system python verson is same as virtual env ? – sahasrara62 Apr 13 '19 at 19:06