Python Forum
Creating Conda env from requirments.txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Conda env from requirments.txt file
#1
I have created a conda environment using the command

conda create -n env-name

Now I can add the packages that I want by putting names and versions on the end of this command,but I want a whole set of packages which are available through a requirements.txt file.

However, the requirements.txt file is not in the conda environment that I just created, and i do not know how to put the requirements.txt file into the newly created conda environment or even if I should.

There may be a work-around.

The requirements.txt is in my base environment, and how do I move it into my newly created conda environment or even if I should.

The may be a method to create the conda env. and have it install only what is specified in the requirements.txt file. with said file not in the conda env.. If there is how do I do it?

I believe it is

conda create --target ...

I do not know the rest.

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Reply
#2
Should add requirements.txt when create environment.
conda create --name foo_env --file requirements.txt
Try to later with conda it can/will be trouble with versions.

Can also use pip,create a clean environment conda create --name bar_env.
Now in activated environment,then do:
conda install pip
This will pull down newest Python version 3.8.2 with pip.
Then can use:
pip install -r requirements.txt
Reply
#3
Old this last statement of course the command is

pip install -r requirements

That requires the requirements.txt file to be inside the newly created
conda environment.

It my case it clearly is not and I do not know how to get it in.

My case the requirements.txt is in the base environment. So maybe this dual command which I saw on line could work.

1. cona create -y --name py33 python==3.30


and


2. conda install -f -y -q --name py33 -c conda-forge --file requirements.txt

would work.

Now I do not know about the "-c conda-forge" option in that command. I know the rest, but what is conda-forge doing in there?

Here is the link where I got the command.

https://stackoverflow.com/questions/5104...target-lib

Any help appreciated. Thanks in advance.

Respectfully,

ErnestTBass
Reply
#4
(Apr-22-2020, 11:22 PM)ErnestTBass Wrote: Now I do not know about the "-c conda-forge" option in that command. I know the rest, but what is conda-forge doing in there?
It use conda-forge to pull down packages.

You don't need to specify python version.
If i use one om my own requirements.txt here
conda create --name foo_env --file requirements.txt
It will pull down Python 3.6.1 the version i used when made this 3-year ago.
Example
G:\Anaconda3\Scripts
λ conda create --name foo_env --file requirements.txt
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: G:\Anaconda3\envs\foo_env

  added / updated specs:
    - beautifulsoup4==4.6.0
    - certifi==2017.4.17
    - chardet==3.0.4
    - colorama==0.3.9
    - idna==2.5
    - lxml==3.8.0
    - py==1.4.34
    - pytest==3.1.3
    - requests==2.18.1
    - urllib3==1.21.1


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    beautifulsoup4-4.6.0       |           py36_0         134 KB  conda-forge
    certifi-2017.4.17          |           py36_0         219 KB  conda-forge
    cffi-1.14.0                |   py36ha419a9e_0         221 KB  conda-forge
    chardet-3.0.4              |py36h9f0ad1d_1006         220 KB  conda-forge
    colorama-0.3.9             |             py_1          14 KB  conda-forge
    cryptography-2.8           |   py36hb32ad35_1         564 KB  conda-forge
    idna-2.5                   |           py36_0         121 KB  conda-forge
    lxml-3.8.0                 |           py36_0         846 KB  conda-forge
    py-1.4.34                  |           py36_0         133 KB  conda-forge
    pysocks-1.7.1              |   py36h9f0ad1d_1          27 KB  conda-forge
    pytest-3.1.3               |           py36_0         302 KB  conda-forge
    python-3.6.10              |he025d50_1009_cpython        20.7 MB  conda-forge
    python_abi-3.6             |          1_cp36m           4 KB  conda-forge
    requests-2.18.1            |           py36_0          91 KB  conda-forge
    setuptools-46.1.3          |   py36h9f0ad1d_0         660 KB  conda-forge
    urllib3-1.21.1             |           py36_1         154 KB  conda-forge
    win_inet_pton-1.1.0        |           py36_0           7 KB  conda-forge
    wincertstore-0.2           |        py36_1003          13 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        24.4 MB

The following NEW packages will be INSTALLED:

  beautifulsoup4     conda-forge/win-64::beautifulsoup4-4.6.0-py36_0
  ca-certificates    conda-forge/win-64::ca-certificates-2020.4.5.1-hecc5488_0
  certifi            conda-forge/win-64::certifi-2017.4.17-py36_0
  cffi               conda-forge/win-64::cffi-1.14.0-py36ha419a9e_0
  chardet            conda-forge/win-64::chardet-3.0.4-py36h9f0ad1d_1006
  colorama           conda-forge/noarch::colorama-0.3.9-py_1
  cryptography       conda-forge/win-64::cryptography-2.8-py36hb32ad35_1
  idna               conda-forge/win-64::idna-2.5-py36_0
  libiconv           conda-forge/win-64::libiconv-1.15-hfa6e2cd_1006
  libxml2            conda-forge/win-64::libxml2-2.9.10-h9ce36c8_0
  libxslt            conda-forge/win-64::libxslt-1.1.33-heafd4d3_0
  lxml               conda-forge/win-64::lxml-3.8.0-py36_0
  openssl            conda-forge/win-64::openssl-1.1.1g-he774522_0
  pip                conda-forge/noarch::pip-20.0.2-py_2
  py                 conda-forge/win-64::py-1.4.34-py36_0
  pycparser          conda-forge/noarch::pycparser-2.20-py_0
  pyopenssl          conda-forge/noarch::pyopenssl-19.1.0-py_1
  pysocks            conda-forge/win-64::pysocks-1.7.1-py36h9f0ad1d_1
  pytest             conda-forge/win-64::pytest-3.1.3-py36_0
  python             conda-forge/win-64::python-3.6.10-he025d50_1009_cpython
  python_abi         conda-forge/win-64::python_abi-3.6-1_cp36m
  requests           conda-forge/win-64::requests-2.18.1-py36_0
  setuptools         conda-forge/win-64::setuptools-46.1.3-py36h9f0ad1d_0
  six                conda-forge/noarch::six-1.14.0-py_1
  urllib3            conda-forge/win-64::urllib3-1.21.1-py36_1
  vc                 conda-forge/win-64::vc-14.1-h869be7e_1
  vs2015_runtime     conda-forge/win-64::vs2015_runtime-14.16.27012-h30e32a0_2
  wheel              conda-forge/noarch::wheel-0.34.2-py_1
  win_inet_pton      conda-forge/win-64::win_inet_pton-1.1.0-py36_0
  wincertstore       conda-forge/win-64::wincertstore-0.2-py36_1003
  zlib               conda-forge/win-64::zlib-1.2.11-h2fa13f4_1006


Proceed ([y]/n)? y


Downloading and Extracting Packages
certifi-2017.4.17    | 219 KB    | ################################################################### | 100%
cffi-1.14.0          | 221 KB    | ################################################################### | 100%
pytest-3.1.3         | 302 KB    | ################################################################### | 100%
beautifulsoup4-4.6.0 | 134 KB    | ################################################################### | 100%
setuptools-46.1.3    | 660 KB    | ################################################################### | 100%
lxml-3.8.0           | 846 KB    | ################################################################### | 100%
urllib3-1.21.1       | 154 KB    | ################################################################### | 100%
python-3.6.10        | 20.7 MB   | ################################################################### | 100%
py-1.4.34            | 133 KB    | ################################################################### | 100%
requests-2.18.1      | 91 KB     | ################################################################### | 100%
idna-2.5             | 121 KB    | ################################################################### | 100%
colorama-0.3.9       | 14 KB     | ################################################################### | 100%
win_inet_pton-1.1.0  | 7 KB      | ################################################################### | 100%
chardet-3.0.4        | 220 KB    | ################################################################### | 100%
wincertstore-0.2     | 13 KB     | ################################################################### | 100%
python_abi-3.6       | 4 KB      | ################################################################### | 100%
cryptography-2.8     | 564 KB    | ################################################################### | 100%
pysocks-1.7.1        | 27 KB     | ################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate foo_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

# Activate and Test
(bar_env) G:\Anaconda3\Scripts
λ activate foo_env

(foo_env) G:\Anaconda3\Scripts
λ python -V
Python 3.6.10

(foo_env) G:\Anaconda3\Scripts
λ python
Python 3.6.10 (default, Mar  5 2020, 10:17:47) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
>>>
>>> bs4.__version__
'4.6.0'
>>> exit()

(foo_env) G:\Anaconda3\Scripts

ErnestTBas Wrote:That requires the requirements.txt file to be inside the newly created
conda environment.

It my case it clearly is not and I do not know how to get it in
It's just the same as over just copy in requirements.txt or give a path.
Reply
#5
Just giving a path to the requirements.txt file would not be enough. You are not going to a new directory, you are going to a new conda environment.

Also,in the command

conda create - --name py33 python=3.3.0

and

conda install -f -y -q --name py33 -c conda-forge --file requirements.txt

I can just leave out

-c conda-forge

?

Also, does the requirements.txt file need to be anything special. I mean it can just have the name of
the modules and their version number, and that's all.

Respectfully,

ErnestTBass
Reply
#6
(Apr-23-2020, 12:49 PM)ErnestTBass Wrote: Just giving a path to the requirements.txt file would not be enough. You are not going to a new directory, you are going to a new conda environment.
No,it will install to the environment use specify dos not matter where the requirements.txt is.
conda create --name one_env --file C:/code/requirements.txt
So here is requirements.txt in a other place,but all requirements will be installed to one_env.


(Apr-23-2020, 12:49 PM)ErnestTBass Wrote: I can just leave out

-c conda-forge
Yes,but it can be smart to use,i have it default as first place to look for packages.
G:\Anaconda3\Scripts
λ conda config --show channels
channels:
  - conda-forge
  - defaults
Look at code in my perivos post,see that Beautifulsoup get pulled down from conda-forge.
beautifulsoup4-4.6.0       |           py36_0         134 KB  conda-forge
Look at this blog for different setup.


(Apr-23-2020, 12:49 PM)ErnestTBass Wrote: Also, does the requirements.txt file need to be anything special. I mean it can just have the name of
the modules and their version number, and that's all.
Can call different name look at this post.

Do you understand the meaning of requirements.txt?
Even if the file is in a Repo dos in not mean that you should use it.
pip install my_package when on PyPi will install all,so here is setup.py used which also install all requirements,the requirements.txt is bi product that is generated
Some Repo will you to use requirements.txt,then is okay to use it.
Reply
#7
I tried the command and it gave no errors. It just did not find any files and quit.

The attached screenshot shows what happened.

I am confused now. The command as I said gave no errors.


conda install -f -y -q --name py33 -c conda-forge --file requirements.txt

The requirements.txt file is in the same directory where I gave the command.

The results as I said are shown in the attached file.

I will use a docker image of jupyter notebook to do this. Mabbe that will work.

respectfully,

ErnestTBass

Attached Files

Thumbnail(s)
   
Reply
#8
Have to know that requirements.txt is more geared against pip,conda has it own way with .yml file <environment-name>.yml.
So the specific versions that are in requirements.txt may not be found in codas Repo packages.
Look at this post in your other thread where i use pip in conda environment.

conda do of course has jupyter,but may not have the specific version that's in requirements.txt
So if i do a simple build:
conda create --name one_env jupyter pandas requests
It will pull down jupyter in newest version.
jupyter_client-6.1.2 | 82 KB     | ################################################################### | 100%
jupyter-1.0.0        | 8 KB      | ################################################################### | 100%
jupyter_core-4.6.3   | 98 KB     | ################################################################### | 100%
jupyter_console-6.1. | 24 KB     | ################################################################### | 100%
Quote:I will use a docker image of jupyter notebook to do this. Mabbe that will work.
It will no difference if use conda and a requirements.txt that has version that's not in conda's Repo.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help creating shell scrip for python file marciokoko 10 1,346 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Confused over Conda Package manager vs PIP JanOlvegg 3 1,205 Mar-09-2023, 02:09 PM
Last Post: JanOlvegg
  How to deactivate correctly a conda environment NoNameoN 2 1,895 Nov-04-2022, 01:43 PM
Last Post: NoNameoN
  Creating csv files from Excel file azizrasul 40 5,580 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  Creating file with images BobSmoss 1 1,382 Jan-08-2022, 08:46 PM
Last Post: snippsat
  SSL error while trying to update conda ilango 0 2,163 Nov-04-2021, 08:38 AM
Last Post: ilango
  Creating csv file from another file pisike 0 1,595 Nov-24-2020, 02:02 PM
Last Post: pisike
  Error: How to to close and restart your shell after running 'conda init' angelica 3 10,259 May-27-2020, 10:00 AM
Last Post: snippsat
  Creating a pdf from file DT2000 4 2,317 Apr-03-2020, 07:16 PM
Last Post: DT2000
  Installing a new package using pip in conda environment firebolt7 1 2,517 Nov-18-2019, 12:31 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020