Enter a Python or Node.js virtual environment
Applications created with the Selectors run in their own environment. Enter it before running npm, pip or gem, or you use the wrong interpreter.
Work on the command line inside an application's virtual environment. Applies to Python, Ruby and Node.js applications created with the cPanel Selectors.
Why it matters
Each application gets its own environment with its own interpreter and its own packages. A plain SSH session uses the system interpreter instead.
Running npm install, pip install or gem install from a plain SSH session
installs against the wrong interpreter, into the wrong location. The command
succeeds, and the application still reports the module as missing.
This is the usual cause of "I installed it and it still says it cannot find it".
Get the command
cPanel gives you the exact command:
- Open Setup Node.js App, Setup Python App or Setup Ruby App.
- Find your application.
- Copy the command shown at the top of its page — labelled Enter to the virtual environment.
It looks like:
source /home/cpaneluser/nodevenv/nodeapp/18/bin/activate && cd /home/cpaneluser/nodeappThe path contains the interpreter version and the application root, so it differs per application. Use the one cPanel shows rather than adapting an example.
Use it
Connect over SSH — see Connect over SSH — and paste the command.
Your prompt changes to show the environment is active. Now npm, pip or gem
target the right interpreter:
npm install express
pip install requestsLeave with deactivate.
After installing
Restart the application from its cPanel page. A running Node.js or Python application does not pick up new packages until it restarts.
If the command fails
No such file or directory— the application was removed or recreated, and the path changed. Copy the current one from cPanel.- The prompt does not change — the
sourcedid not run. Usesource, notsh, and do not run it in a subshell. - Still the wrong version — check with
which nodeorwhich python. It should point inside your home directory, not/usr/bin.
Related
Use SSH keys with PuTTY on Windows
Generate a key with PuTTYgen, authorise it on your account, and connect — including the format conversion that catches people out.
Install PEAR packages
Add PEAR packages through cPanel's PHP PEAR Packages interface, and know that PEAR is largely superseded by Composer.