nodeenv icon indicating copy to clipboard operation
nodeenv copied to clipboard

nodeenv -p: "No python virtualenv is available" on Mac OS X

Open ovanes opened this issue 10 years ago • 11 comments

Just used mkvirtualenv ntest and issuing afterwards. This creates a new python environment and activates it (directory of this environment is somewhere in my home, but not current).

I use nodeenv -p to let nodeenv create a node.js environment in the current active Python environment, but I get an error: "No python virtualenv is available"

ovanes avatar Sep 13 '15 16:09 ovanes

Would you be able to provide full sequence of commands? Here's my try:

➥ virtualenv testenv
➥ . testenv/bin/activate
(testenv) ➥ pip install nodeenv
(testenv) ➥ nodeenv --version
0.13.6
(testenv) ➥ nodeenv -p --prebuilt
 * Install node (4.0.0)... done.
 * Appending data to ~/Projects/nodeenv/testenv/bin/activate
(testenv) ➥ node -v
v4.0.0

ekalinin avatar Sep 13 '15 18:09 ekalinin

$ mkvirtualenv ntest
> Overwriting ntest/lib/python2.7/site.py with new content
> New python executable in ntest/bin/python2.7
> Not overwriting existing python script ntest/bin/python (you must use ntest/bin/python2.7)
> Installing setuptools, pip, wheel...done.
> Overwriting ntest/bin/activate with new content
> Overwriting ntest/bin/activate_this.py with new content
(ntest): $ nodeenv -p
> No python virtualenv is available

mkvirtualenv automatically activates ntest after it was created.

ovanes avatar Sep 13 '15 20:09 ovanes

mkvirtualenv automatically activates ntest after it was created.

Seems, you should install nodeenv first before try to use it.

ekalinin avatar Sep 14 '15 08:09 ekalinin

Well, I was thinking it'd be enough to install nodeenv globally and just "convert" python's virtualenv to node.js environment...

I wonder, why global nodeenv can't use the currently selected environment? Using the which python gives you the fully qualified path to the python interpreter. If that interpreter is in virtualenv you'll get the path to it. Additionally, virtualenv exports the following envvar: VIRTUAL_ENV=/Users/ovanes/python_envs/ntest.

ovanes avatar Sep 14 '15 09:09 ovanes

It's VPS on KVM

Description: Debian GNU/Linux 7.9 (wheezy) nodeenv --version 0.13.6

nodeenv node
 * Install node (5.5.0).. Traceback (most recent call last):
  File "/home/kichawa/test_nodeenv/bin/nodeenv", line 9, in <module>
    load_entry_point('nodeenv==0.13.6', 'console_scripts', 'nodeenv')()
  File "/home/kichawa/test_nodeenv/local/lib/python2.7/site-packages/nodeenv.py", line 891, in main
    create_environment(env_dir, opt)
  File "/home/kichawa/test_nodeenv/local/lib/python2.7/site-packages/nodeenv.py", line 732, in create_environment
    install_node(env_dir, src_dir, opt)
  File "/home/kichawa/test_nodeenv/local/lib/python2.7/site-packages/nodeenv.py", line 608, in install_node
    build_node_from_src(env_dir, src_dir, node_src_dir, opt)
  File "/home/kichawa/test_nodeenv/local/lib/python2.7/site-packages/nodeenv.py", line 577, in build_node_from_src
    callit([make_cmd] + make_opts, opt.verbose, True, node_src_dir, env)
  File "/home/kichawa/test_nodeenv/local/lib/python2.7/site-packages/nodeenv.py", line 461, in callit
    % (cmd_desc, proc.returncode))
OSError: Command make --jobs=2 failed with error code 2

kichawa avatar Jan 21 '16 22:01 kichawa

Hey @kichawa

Would you be able to provide more details?

ekalinin avatar Jan 22 '16 08:01 ekalinin

i did. Say if you want more.

kichawa avatar Jan 22 '16 11:01 kichawa

Commands executed in Terminal running on OS X 10.12.6.

Base Python 2.7.14 installed using PyEnv:

$ pip --version
pip 9.0.1 from /Users/kennytrytek/.pyenv/versions/2.7.14/Python.framework/Versions/2.7/lib/python2.7/site-packages (python 2.7)

$ easy_install --version
setuptools 28.8.0 from /Users/kennytrytek/.pyenv/versions/2.7.14/Python.framework/Versions/2.7/lib/python2.7/site-packages (Python 2.7)

$ pip freeze
-f file:////Users/kennytrytek/.pip/cache/
nodeenv==1.2.0
pbr==3.1.1
six==1.11.0
stevedore==1.27.1
virtualenv==15.1.0
virtualenv-clone==0.2.6
virtualenvwrapper==4.8.2

$ brew list | grep py
pyenv
pyenv-virtualenvwrapper

$ pyenv versions
  system
  2.7.13
* 2.7.14 (set by PYENV_VERSION environment variable)
  3.4.5
  3.6.0

Create new venv:

(jflsk) $ deactivate

$ rmvirtualenv jflsk
Removing jflsk...

$ mkvirtualenv jflsk -a .
Running virtualenv with interpreter /Users/kennytrytek/.pyenv/versions/2.7.14/bin/python
New python executable in /Users/kennytrytek/virtualenv/jflsk/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/kennytrytek/virtualenv/jflsk/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/kennytrytek/virtualenv/jflsk/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/kennytrytek/virtualenv/jflsk/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/kennytrytek/virtualenv/jflsk/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/kennytrytek/virtualenv/jflsk/bin/get_env_details
Setting project for jflsk to /Users/kennytrytek/virtualenv

$ easy_install --upgrade setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Downloading https://pypi.python.org/packages/4f/12/fe19686c43d82c2101c70b917185682f4fc907cbfc9290368ecace403ad6/setuptools-36.7.1.zip#md5=4e1e43194ea26c9800f091cb7c0ff486
Best match: setuptools 36.7.1
Processing setuptools-36.7.1.zip
Writing /var/folders/f2/9r88cqg530b11d6j2z_9fq8w0000gp/T/easy_install-bNtHAy/setuptools-36.7.1/setup.cfg
Running setuptools-36.7.1/setup.py -q bdist_egg --dist-dir /var/folders/f2/9r88cqg530b11d6j2z_9fq8w0000gp/T/easy_install-bNtHAy/setuptools-36.7.1/egg-dist-tmp-Vtwz2D
warning: no files found matching '*' under directory 'setuptools/_vendor'
Copying setuptools-36.7.1-py2.7.egg to /Users/kennytrytek/virtualenv/jflsk/lib/python2.7/site-packages
Adding setuptools 36.7.1 to easy-install.pth file
Installing easy_install script to /Users/kennytrytek/virtualenv/jflsk/bin
Installing easy_install-2.7 script to /Users/kennytrytek/virtualenv/jflsk/bin

Installed /Users/kennytrytek/virtualenv/jflsk/lib/python2.7/site-packages/setuptools-36.7.1-py2.7.egg
Processing dependencies for setuptools
Finished processing dependencies for setuptools

$ pip install --upgrade pip
Requirement already up-to-date: pip in ./jflsk/lib/python2.7/site-packages

$ pip freeze

There is definitely some unexpected behavior here:

(jflsk) $ nodeenv -p
No python virtualenv is available

(jflsk) $ source jflsk/bin/activate

(jflsk) $ nodeenv -p
No python virtualenv is available

---------------------

(jflsk) $ deactivate

$ source jflsk/bin/activate

(jflsk) $ nodeenv -p
No python virtualenv is available

(jflsk) $ pip install nodeenv
Collecting nodeenv
Installing collected packages: nodeenv
Successfully installed nodeenv-1.2.0

(jflsk) $ nodeenv -p
No python virtualenv is available

---------------------

(jflsk) $ deactivate

$ source jflsk/bin/activate

(jflsk) $ nodeenv -p
 * Install prebuilt node (9.1.0) ..... done.
 * Appending data to /Users/kennytrytek/virtualenv/jflsk/bin/../bin/activate

(jflsk) $ 

Some observations:

  1. nodeenv must be installed in the virtual environment you want to use. It cannot exist only in the base Python environment that the virtualenv is part of.
  2. The virtual environment must have nodeenv installed before activation. nodeenv that has been installed into an already-activated environment will not work until the environment is deactivated and reactivated again.

How to make it work:

  1. Create your virtualenv.
  2. Install nodeenv.
  3. Deactivate your virtualenv.
  4. Activate your virtualenv.
  5. nodeenv -p

kennytrytek-wf avatar Nov 13 '17 14:11 kennytrytek-wf

Same thing with pipenv that @kennytrytek-wf said, the key thing being: after installing nodeenv into the venv, exit the shell, then re-enter the shell

$ uname -a

Linux vinex 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 x86_64

$ cat /etc/lsb-release |grep REL

DISTRIB_RELEASE=17.10

$ pipenv install --three

Creating a virtualenv for this project...
Pipfile: /home/me/myproject/Pipfile
Using /usr/bin/python3 (3.6.3) to create virtualenv...
⠋Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/me/.virtualenvs/DiuExKA5/bin/python3
Also creating executable in /home/me/.virtualenvs/DiuExKA5/bin/python
Installing setuptools, pip, wheel...done.
Setting project for DiuExKA5 to /home/me/myproject
Virtualenv location: /home/me/.virtualenvs/DiuExKA5
Creating a Pipfile for this project...
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock (ca72e7)!
Installing dependencies from Pipfile.lock (ca72e7)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

$ pipenv shell

Launching subshell in virtual environment…
 . /home/me/.virtualenvs/DiuExKA5/bin/activate

❲p❳ DiuExKA5 | ~/pyproject $ nodeenv -p --prebuilt

No python virtualenv is available

❲p❳ DiuExKA5 | ~/pyproject | 2 $ pipenv install nodeenv

Installing nodeenv...
Collecting nodeenv
  Downloading https://files.pythonhosted.org/packages/36/ca/1a635c6cd6049105fadfdc05c8de364f368fcc7aebad3081dd8ccb0c5c7f/nodeenv-1.3.2.tar.gz
Building wheels for collected packages: nodeenv
  Running setup.py bdist_wheel for nodeenv: started
  Running setup.py bdist_wheel for nodeenv: finished with status 'done'
  Stored in directory: /home/stav/.cache/pipenv/wheels/f3/91/e8/836a7b82342fbb2925f1022678a857970820595faae108182f
Successfully built nodeenv
Installing collected packages: nodeenv
Successfully installed nodeenv-1.3.2
Adding nodeenv to Pipfile's [packages]...
Pipfile.lock (ca72e7) out of date, updating to (2662ea)...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock (2662ea)!
Installing dependencies from Pipfile.lock (2662ea)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00

❲p❳ DiuExKA5 | ~/pyproject $ nodeenv -p --prebuilt

No python virtualenv is available

❲p❳ DiuExKA5 | ~/pyproject | 2 $ which nodeenv

/home/me/.virtualenvs/DiuExKA5/bin/nodeenv

❲p❳ DiuExKA5 | ~/pyproject | 2 $ nodeenv --version

1.3.2

❲p❳ DiuExKA5 | ~/pyproject $ exit

$ pipenv shell

Launching subshell in virtual environment…
. /home/me/.virtualenvs/DiuExKA5/bin/activate

❲p❳ DiuExKA5 | ~/pyproject $ nodeenv -p --prebuilt

* Install prebuilt node (10.9.0) ..... done.
* Appending data to /home/me/.virtualenvs/DiuExKA5/bin/activate
* Appending data to /home/me/.virtualenvs/DiuExKA5/bin/activate.fish

stav avatar Aug 18 '18 21:08 stav

I can also confirm @kennytrytek-wf on virtualenv:

1. nodeenv must be installed in the virtual environment you want to use. It cannot exist only in the base Python environment that the virtualenv is part of.

2. The virtual environment must have nodeenv installed before activation. nodeenv that has been installed into an already-activated environment will not work until the environment is deactivated and reactivated again.

How to make it work:

1. Create your virtualenv.

2. Install nodeenv.

3. Deactivate your virtualenv.

4. Activate your virtualenv.

5. `nodeenv -p`

goekce avatar Apr 25 '22 08:04 goekce

An alternative is to use nodeenv to install both Node.js and packages, eg:

$ cat python-requirements.txt 
nodeenv==1.7.0
pre-commit==2.20.0
$ cat node-requirements.txt 
npm-groovy-lint
$ python3 -m venv venv
$ . venv/bin/activate
(venv) $ pip install -r python-requirements.txt
(venv) $ . venv/bin/activate
(venv) $ nodeenv -p -r node-requirements.txt --node lts
(venv) $ which pre-commit
.../venv/bin/pre-commit
(venv) $ which npm-groovy-lint
.../venv/bin/npm-groovy-lint
(venv) $ which npm
.../venv/bin/npm
(venv) $ which npx
.../venv/bin/npx

The second call to activate will get read of any "python virtualenv not found" errors.

chgans avatar Aug 09 '22 04:08 chgans