firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.04k stars 952 forks source link

Trying to install functions python runtime on Windows resuslts in OSError #6625

Open muddi900 opened 1 year ago

muddi900 commented 1 year ago

[REQUIRED] Environment info

firebase-tools: 12.3.0

Platform: Windows 11

[REQUIRED] Test case

Run firebase init on Windows.

[REQUIRED] Steps to reproduce

  1. Run firebase init
  2. Select Functions
  3. Select Python
  4. Select Yes on install dependencies

[REQUIRED] Expected behavior

It should install.

[REQUIRED] Actual behavior

[2023-06-02T04:49:57.687Z] Running command with virtualenv: command="C:\src\maiker\functions\venv\Scripts\activate.bat", args=["","&&","pip3","install","--upgrade","pip"]
Requirement already satisfied: pip in c:\src\maiker\functions\venv\lib\site-packages (22.0.4)
Collecting pip
  Using cached pip-23.1.2-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.0.4
    Uninstalling pip-22.0.4:
      Successfully uninstalled pip-22.0.4
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'C:\\Users\\muddi\\AppData\\Local\\Temp\\pip-uninstall-0as7cbwm\\pip3.exe'
Check the permissions.

[2023-06-02T04:50:10.281Z] Error: spawn "C:\src\maiker\functions\venv\Scripts\activate.bat" ENOENT
    at notFoundError (C:\Users\muddi\AppData\Roaming\nvm\v16.17.1\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\muddi\AppData\Roaming\nvm\v16.17.1\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\muddi\AppData\Roaming\nvm\v16.17.1\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

Error: An unexpected error has occurred.

Powershell is running as admin

image

davidbeg commented 1 year ago

Having the same issue, would appreciate a workaround!

Jackilion commented 1 year ago

I ran into the same problem. I used python 3.9, but the firebase package requires python >3.10. Upgrading and updating the path variables solved the issue.

If it still doesn't work: The problem comes from the "python.js" file, located under AppData\Roaming\npm\node_modules\firebase-tools\lib\functions

Line 29 onwards:

    const install = await (0, prompt_1.promptOnce)({
        name: "install",
        type: "confirm",
        message: "Do you want to install dependencies now?",
        default: true,
    });
    if (install) {
        const upgradeProcess = (0, python_2.runWithVirtualEnv)(["pip3", "install", "--upgrade", "pip"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
        await new Promise((resolve, reject) => {
            upgradeProcess.on("exit", resolve);
            upgradeProcess.on("error", reject);
        });
        const installProcess = (0, python_2.runWithVirtualEnv)([(0, python_1.getPythonBinary)(python_1.LATEST_VERSION), "-m", "pip", "install", "-r", "requirements.txt"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
        await new Promise((resolve, reject) => {
            installProcess.on("exit", resolve);
            installProcess.on("error", reject);
        });
    }
}

It seems that after you hit "yes" to installing dependencies, the script tries to upgrade pip, and then install the packages specified under "requirements.txt". It is the upgrade pip command that fails.

If you simply hit "no", the setup completes. You can then go ahead and pip install requirements.txt on your own. (This is how I found out my python version was too old - it gave me a more helpful error message when I did it manually. After upgrading python I tried to go through the setup again and this time it completed.)

muddi900 commented 1 year ago

My environment is 3.10 on Windows.

Thank you

On Wed, Jun 14, 2023 at 2:42 PM Jackilion @.***> wrote:

I ran into the same problem. I used python 3.9, but the firebase package requires python >3.10. Upgrading and updating the path variables solved the issue.

If it still doesn't work: The problem comes from the "python.js" file, located under AppData\Roaming\npm\node_modules\firebase-tools\lib\functions

Line 29 onwards:

const install = await (0, prompt_1.promptOnce)({
    name: "install",
    type: "confirm",
    message: "Do you want to install dependencies now?",
    default: true,
});
if (install) {
    const upgradeProcess = (0, python_2.runWithVirtualEnv)(["pip3", "install", "--upgrade", "pip"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
    await new Promise((resolve, reject) => {
        upgradeProcess.on("exit", resolve);
        upgradeProcess.on("error", reject);
    });
    const installProcess = (0, python_2.runWithVirtualEnv)([(0, python_1.getPythonBinary)(python_1.LATEST_VERSION), "-m", "pip", "install", "-r", "requirements.txt"], config.path(setup.functions.source), {}, { stdio: ["inherit", "inherit", "inherit"] });
    await new Promise((resolve, reject) => {
        installProcess.on("exit", resolve);
        installProcess.on("error", reject);
    });
}

}

It seems that after you hit "yes" to installing dependencies, the script tries to upgrade pip, and then install the packages specified under "requirements.txt". It is the upgrade pip command that fails.

If you simply hit "no", the setup completes. You can then go ahead and pip install requirements.txt on your own. (This is how I found out my python version was too old - it gave me a more helpful error message when I did it manually. After upgrading python I tried to go through the setup again and this time it completed.)

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-tools/issues/6625, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2VVZW7TFPADEQ7KDF3JUTXLIHZFANCNFSM6AAAAAAZFLHTII . You are receiving this because you authored the thread.Message ID: @.***>

B2Gdevs commented 1 year ago

Same issue. I have tried numerous times, here are some logs from the firebase-debug.log file.

[info] i  Skipping write of functions/requirements.txt 
[info] i  Skipping write of functions/.gitignore 
[info] i  Skipping write of functions/main.py 
[debug] [2023-06-15T02:14:56.546Z] Running command with virtualenv: command="C:\Users\stacho\Documents\custominstallations\action_items_ai\functions\venv\Scripts\activate.bat", args=["","&&","pip3","install","--upgrade","pip"]
[debug] [2023-06-15T02:14:57.427Z] Error: spawn "C:\Users\stacho\Documents\custominstallations\action_items_ai\functions\venv\Scripts\activate.bat" ENOENT
    at notFoundError (C:\Users\stacho\AppData\Roaming\nvm\v18.13.0\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\stacho\AppData\Roaming\nvm\v18.13.0\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:40:16)
    at cp.emit (C:\Users\stacho\AppData\Roaming\nvm\v18.13.0\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:27:25)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
[error] 
[error] Error: An unexpected error has occurred.

^^ the above fails just to activate the environment

Then when I actually activate the environment by just doing source venv/Scripts/activate

I get the below

[info] i  Skipping write of functions/requirements.txt 
[info] i  Skipping write of functions/.gitignore 
[info] i  Skipping write of functions/main.py 
[debug] [2023-06-15T02:19:23.096Z] Error: spawn python.exe ENOENT
    at notFoundError (C:\Users\stacho\AppData\Roaming\nvm\v18.13.0\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\stacho\AppData\Roaming\nvm\v18.13.0\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:40:16)
    at cp.emit (C:\Users\stacho\AppData\Roaming\nvm\v18.13.0\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:27:25)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)
[error] 
[error] Error: An unexpected error has occurred.

Here is some other info, hopefully it helps

[debug] [2023-06-15T02:19:12.209Z] ----------------------------------------------------------------------
[debug] [2023-06-15T02:19:12.210Z] Command:       C:\Program Files\nodejs\node.exe C:\Program Files\nodejs\node_modules\firebase-tools\lib\bin\firebase.js init
[debug] [2023-06-15T02:19:12.211Z] CLI Version:   12.3.1
[debug] [2023-06-15T02:19:12.211Z] Platform:      win32
[debug] [2023-06-15T02:19:12.211Z] Node Version:  v18.13.0
[debug] [2023-06-15T02:19:12.212Z] Time:          Wed Jun 14 2023 21:19:12 GMT-0500 (Central Daylight Time)
[debug] [2023-06-15T02:19:12.212Z] ----------------------------------------------------------------------
[debug] 
[debug] [2023-06-15T02:19:12.269Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
William-LP commented 1 year ago

A fresh install of python fixed it for me.

hmalik144 commented 1 year ago
  1. Open Powershell as admin
  2. Run command: Set-ExecutionPolicy RemoteSigned
  3. Go back to terminal in project
  4. Run command: firebase init
  5. navigate though: select 'functions' -> language = python -> (go through until Do you want to install dependencies now?)
  6. Do you want to install dependencies now? Yes

activiate.bat should now be in /functions/venv/Scripts

jelling commented 1 year ago

Same spawn "C:\src\maiker\functions\venv\Scripts\activate.bat" ENOENT issue. Fix was to reinit the Firebase project. I suspect this worked because Firebase then created the venv directory as it wanted.

Odd part was that I had a working environment as of a week or two ago and had previously deployed the functions.

sieutruc commented 1 year ago

I got the same error , any solution for that?

B2Gdevs commented 1 year ago

Yep. Switched to google cloud run. Basically the same thing but I can control the binaries available and environment variables

On Thu, Aug 17, 2023 at 9:29 AM sieutruc @.***> wrote:

I got the same error , any solution for that?

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-tools/issues/6625, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF756PDC3E7Q6O6PCRVCR6DXVYTDVANCNFSM6AAAAAAZFLHTII . You are receiving this because you commented.Message ID: @.***>

Anquuni commented 1 year ago

I have the same error, is there still no solution?

sieutruc commented 1 year ago

@Anquuni a workaround is to reinstall the Python that fixed for me.

maximalniq commented 1 year ago

Instal python >3.10 , and restart system

johnnyoshika commented 12 months ago

I ran into a similar. The problem occurs in this firebase init functions step if I choose to install dependencies:

Do you want to install dependencies now? Yes

The system cannot find the path specified.

Error: An unexpected error has occurred.

Inspecting firebase-debug.log shows this:

[debug] [2023-12-07T17:48:47.757Z] Running command with virtualenv: command="C:\Users\{path redacted}\venv\Scripts\activate.bat", args=["","&&","pip3","install","--upgrade","pip"]
[debug] [2023-12-07T17:48:48.472Z] Error: spawn "C:\Users\{path redacted}\venv\Scripts\activate.bat" ENOENT
    at notFoundError (C:\Users\{path redacted}\AppData\Roaming\nvm\v16.13.2\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\{path redacted}\AppData\Roaming\nvm\v16.13.2\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\{path redacted}\AppData\Roaming\nvm\v16.13.2\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
[error] 
[error] Error: An unexpected error has occurred.

This error occurs whether I create the venv virtual environment in advance or not. I got around this by selecting No when firebase init asks me whether I want to install dependencies:

Do you want to install dependencies now? No

I then install dependencies manually inside the virtual environment with:

pip install -r requirements.txt
ivanandresdiaz commented 12 months ago

I was facing some problems, I created a video. Maybe it can help some of you https://www.youtube.com/watch?v=q_sayYt50oM

paulo101977 commented 11 months ago

I manually installed the packages using Python on my machine, instead of the binaries that Firebase downloads:

python -m pip install -r requirements.txt -t ./venv/Lib/site-packages/

This command must be run within the directory where the requirements.txt

taeold commented 11 months ago

Hello. Sorry for all the issues. It looks like the Firebase CLI isn't a reporting a clear error message when some of the necessary tools, like python.exe, pip3, venv/scripts/activate.bat, can't be access by the CLI. That would explain some of the reports where a fresh install of python helps resolve the issue.

We are going to foucs on making the error messages more clear so that your system has all the necessary program it needs to run the emulator. Thanks for your patience as we try to improve the error messaging.

harryob2 commented 11 months ago

I was facing some problems, I created a video. Maybe it can help some of you https://www.youtube.com/watch?v=q_sayYt50oM

thanks for this, this fixed it for me.

mystardustcaptain commented 5 months ago

I ran into a similar. The problem occurs in this firebase init functions step if I choose to install dependencies:

Do you want to install dependencies now? Yes

The system cannot find the path specified.

Error: An unexpected error has occurred.

Inspecting firebase-debug.log shows this:

[debug] [2023-12-07T17:48:47.757Z] Running command with virtualenv: command="C:\Users\{path redacted}\venv\Scripts\activate.bat", args=["","&&","pip3","install","--upgrade","pip"]
[debug] [2023-12-07T17:48:48.472Z] Error: spawn "C:\Users\{path redacted}\venv\Scripts\activate.bat" ENOENT
    at notFoundError (C:\Users\{path redacted}\AppData\Roaming\nvm\v16.13.2\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\{path redacted}\AppData\Roaming\nvm\v16.13.2\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\{path redacted}\AppData\Roaming\nvm\v16.13.2\node_modules\firebase-tools\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
[error] 
[error] Error: An unexpected error has occurred.

This error occurs whether I create the venv virtual environment in advance or not. I got around this by selecting No when firebase init asks me whether I want to install dependencies:

Do you want to install dependencies now? No

I then install dependencies manually inside the virtual environment with:

pip install -r requirements.txt

Appreciate, this works.