conda-forge / compilers-feedstock

A conda-smithy repository for compilers.
BSD 3-Clause "New" or "Revised" License
9 stars 17 forks source link

When installing`c-compiler` on Windows, VS 2022 Build Tools init file is not installed #66

Open Dr-Irv opened 3 months ago

Dr-Irv commented 3 months ago

Solution to issue cannot be found in the documentation.

Issue

Not sure if this issue goes here or somewhere else.

This is on Windows 11. First you install the latest Visual Studio 2022 Build Tools. No other Visual Studio is installed.

If you create a new environment, and do conda install c-compiler -c conda-forge, the batch file that is installed in \envs\pandas-dev\etc\conda\activate.d is vs2019_compiler_vars.bat which does not work with Microsoft Visual Studio 2022 Build Tools.

Installing c-compiler causes vs2019_win-x64 to be installed. I would have expected vs2022_win-x64 to be installed.

If I first install vs2022_win-x64 , then c-compiler, then remove \envs\pandas-dev\etc\conda\activate.d\vs2019_compiler_vars.bat, then edit vs2022_compiler_vars.bat to use version 14.41, instead of 14.40, I think it will work properly.

Trying to do this for building pandas on Windows.

Installed packages

# Name                    Version                   Build  Channel
bzip2                     1.0.8                h2bbff1b_6
c-compiler                1.7.0                hcfcfb64_1    conda-forge
ca-certificates           2024.7.4             h56e8100_0    conda-forge
expat                     2.6.2                hd77b12b_0
libffi                    3.4.4                hd77b12b_1
openssl                   3.3.1                h2466b09_2    conda-forge
pip                       24.2            py312haa95532_0
python                    3.12.4               h14ffc60_1
setuptools                72.1.0          py312haa95532_0
sqlite                    3.45.3               h2bbff1b_0
tk                        8.6.14               h0416ee5_0
tzdata                    2024a                h04d1e81_0
ucrt                      10.0.22621.0         h57928b3_0    conda-forge
vc                        14.40                h2eaa2aa_0
vc14_runtime              14.40.33810         ha82c5b3_20    conda-forge
vs2015_runtime            14.40.33810         h3bf8584_20    conda-forge
vs2019_win-64             19.29.30139         he1865b1_20    conda-forge
vswhere                   3.1.7                h57928b3_0    conda-forge
wheel                     0.43.0          py312haa95532_0
xz                        5.4.6                h8cc25b3_1
zlib                      1.2.13               h8cc25b3_1

Environment info

active environment : compiler-test
    active env location : C:\Condadirs\envs\compiler-test
            shell level : 1
       user config file : C:\Users\Irv\.condarc
 populated config files : C:\Users\Irv\.condarc
          conda version : 24.7.1
    conda-build version : 24.5.1
         python version : 3.12.3.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=skylake
                          __conda=24.7.1=0
                          __cuda=12.2=0
                          __win=0=0
       base environment : C:\Anaconda3  (read only)
      conda av data dir : C:\Anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
                          http://conda.anaconda.org/gurobi/win-64
                          http://conda.anaconda.org/gurobi/noarch
          package cache : C:\Condadirs\pkgs
       envs directories : C:\Condadirs\envs
                          C:\Users\Irv\.conda\envs
                          C:\Anaconda3\envs
                          C:\Users\Irv\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/24.7.1 requests/2.32.2 CPython/3.12.3 Windows/11 Windows/10.0.22631 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8 aau/0.4.4 c/. s/. e/.
          administrator : False
             netrc file : None
           offline mode : False
AnujChitari commented 2 months ago

It is absolutely possible to develop with Visual Studio 2022 Build Tools on Windows. The issue you're encountering with the init file not being installed is likely an isolated problem that can be resolved with the right steps.

1)Verify Build Tools Installation Make sure that Visual Studio 2022 Build Tools are properly installed:

Open the Visual Studio Installer. Ensure you have Visual Studio Build Tools 2022 installed. Under Workloads, make sure Desktop development with C++ is selected.

2)Install Required Components Sometimes, specific components might be missing: In the Visual Studio Installer, click Modify on the Build Tools installation. Ensure that MSVC v143 - VS 2022 C++ x64/x86 build tools and C++ CMake tools for Windows are selected.

3)Run the Build Tools Command Line To check if the command-line tools are working, open the Developer Command Prompt for Visual Studio or a regular Command Prompt with the appropriate environment setup:

Open Start Menu, search for Developer Command Prompt for Visual Studio 2022, and run it. Try running cl.exe to see if the compiler is recognized.

4)Environment Variables Ensure environment variables are set up correctly: Check that paths to cl.exe, link.exe, and other tools are in your PATH environment variable.

AnujChitari commented 2 months ago

I hope this should work!

Dr-Irv commented 2 months ago

I hope this should work!

This solves the problem, but is not solving the fundamental problem, which is when you install c-compiler from conda-forge, it doesn't install the correct script in \envs\pandas-dev\etc\conda\activate.d\ that causes the conda environment to be properly updated upon activation with the right paths.

The issue is that c-compiler is installing vs2019_win-64 rather than vs2022_win-64

atwilso commented 1 month ago

I also have this problem.

Windows Server 2016 machine with Visual Studio 2022 installed and a fresh install of Anaconda 2024.06-1. When I conda env create my environment, vs2019_win-64 gets installed. After that, conda activate produces errors and does not find cl.exe and friends.

After I conda install vs2022_win-64 and conda activate my_vs2022_env, cl.exe winds up on the path but the CMake default generator is set to Visual Studio 16 2019. This causes CMake to fail because it can't find VS2019.

Removing envs/my_vs2022_env/etc/conda/activate.d/vs2019_compiler_vars.bat and resetting my shell seems to have fixed the issue for now. How can we solve this properly?

atwilso commented 1 month ago

I've just confirmed that removing vs2019_compiler_vars.bat causes CMAKE_GENERATOR and friends to be set correctly for Visual Studio 2022.

atwilso commented 1 month ago

On reflection, I think the root cause here is the fact that conda install -c conda-forge compilers does not (and at present cannot) actually do what it says on the box when running on Windows: that is, install the compiler used to build the ecosystem. Instead, we're in a situation where we can install some packages related to a particular version of Visual C++, but we have no way to install the compiler itself.

I don't have a clear answer for what the Right Thing would be here. The best idea I've got is to avoid installing compilers so that I don't pick up the dependency on vs2019_win-64. Then, when I run Visual Studio 2022, I'm still running some small risk of ABI incompatibility but at least I'm not tripping over the vs2019 batch files.

It sure would be convenient if Microsoft would provide a conda-forge package that actually installs VC++ but I'm going to guess that that isn't on their product roadmap.

tobiasdiez commented 1 month ago

For me even with the workarounds of removing the old vs2019_compiler_vars.bat file, cl.exe was not found after conda activate in a normal powershell console. The conda install command prints at the end:

C:\Program Files\Microsoft Visual Studio\2022\Community>if "14.41-14.41" == "14.40-14.41" (CALL "VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.41 10.0.22621.0 )  else (CALL "VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.41 10.0.22621.0 )
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.11.5
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

So it seems to detect that I've VS 2022 installed.

Everything works, however, if you activate conda in the "Developer Command Prompt".

Is there a way to make it work in "normal" consoles?

atwilso commented 3 weeks ago

My current workaround for this issue is to install vs2022_win-64 rather than compilers, cxx-compiler or c-compiler. This does require me to have Windows-specific environment.yml files, but I have to use those anyway at the moment.