From conda create requirements.txt for pip3
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Moving between conda and pip environments is a common need when deploying applications or collaborating with developers who do not use Anaconda. Conda tracks packages from its own channels alongside pip-installed packages, and exporting that environment into a pip-compatible requirements.txt requires careful handling. This article covers several approaches, from quick one-liners to more robust filtering strategies.
Using pip freeze Inside a Conda Environment
The simplest method is activating the conda environment and running pip freeze. This outputs every pip-visible package in the standard package==version format.
The resulting file looks like this.
This works because conda environments include a pip installation. Any package installed through either conda install or pip install within the environment will appear in the output. However, pip freeze may miss packages installed exclusively through conda channels that have no PyPI equivalent.
Using conda list --export
The conda list --export command outputs all packages in the environment, including their conda channel information.
The output uses a conda-specific format.
This format is not pip-compatible because it uses single = signs and includes build strings. To convert it into a pip-friendly format, you can filter and reformat.
This command strips comment lines, removes internal conda packages (those starting with _), and converts the version separator from conda's =version=build to pip's ==version.
Using conda env export
For a full environment specification including the conda channel and any pip-installed packages, use conda env export.
The YAML output separates conda packages from pip packages.
To extract only the pip section into a requirements.txt, you can parse the YAML file.
Filtering Out Conda-only Packages
Some packages in a conda environment exist only in conda channels and have no PyPI equivalent. These include low-level libraries like libffi, openssl, readline, and zlib. Including them in a requirements.txt causes pip install to fail.
A more reliable alternative is to cross-reference against PyPI. The pip install command will simply skip packages it cannot find, but this produces error messages. A cleaner approach uses a script.
Handling Channel-specific Package Names
Some packages have different names between conda and PyPI. For example, pillow on conda may appear as pil or pillow depending on the channel, while PyPI uses Pillow. A mapping dictionary handles these cases.
Apply this mapping during the export process to prevent pip install -r requirements.txt failures caused by unrecognized package names.
Quick Reference for Export Commands
The --no-builds flag in method 3 omits build hashes, producing cleaner output that is easier to read and more portable across platforms.
Common Pitfalls
- Including conda system libraries - Packages like
libffi,openssl, andzlibexist only in conda channels. Adding them torequirements.txtcauses pip installation failures because they have no PyPI equivalent. - Confusing version separators - Conda uses single
=between name, version, and build string, while pip uses==. Forgetting to convert the separator produces an invalid requirements file. - Missing pip-installed packages in conda export - If you install packages with pip inside a conda environment without the
--no-depsflag, conda may not track them. Always check bothconda listandpip freezeoutputs. - Platform-specific packages - Conda environments often include OS-specific packages (such as
mklon Intel systems). These packages may not be available on the target platform and should be removed from the requirements file. - Ignoring package name differences - Package names sometimes differ between conda and PyPI (for example,
pytorchversustorch). Failing to translate these names causes silent installation of wrong packages or outright failures.
Summary
pip freezeinside an activated conda environment is the quickest way to generate a pip-compatiblerequirements.txt.conda list --exportincludes all packages but requires format conversion from conda's=version=buildto pip's==version.conda env exportproduces a full YAML specification that separates conda and pip dependencies.- Filter out conda-only system libraries like
libffi,openssl, andzlibthat have no PyPI counterparts. - Map package names that differ between conda and PyPI, such as
pytorchtotorch, to prevent installation failures. - Use
--no-buildswithconda env exportfor cleaner, more portable output without platform-specific build hashes.

