Python is not recognized in the VSC integrated terminal - vscode-extensions

Environment data
VS Code version: 1.47.3
Extension version (available under the Extensions sidebar): XXX
OS and version: Windows Server 2019
Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.8 and Python 3.8.4 (downloaded from Python.org)
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): NA
Relevant/affected Python packages and their versions:
Relevant/affected Python-related VS Code extensions and their versions: Python 2020.7.96456 and Shell launcher 0.4.1
Value of the python.languageServer setting: None
Expected behaviour
When I select the Python Interpreter version, I expect to get the selected version in the VSC integrated terminal.
Actual behaviour
When I type Python in the integrated terminal, the command is not recognized.
In my user settings, I'm setting the PATH environment variable (I removed the path for the python directory here). Also I'm excluding myself from the A/B pythonPath testing.
Steps to reproduce:
Logs
Output from Python output channel
> conda --version
> pyenv root
> python3.7 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.7 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.6 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -2 c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~\anaconda3\Scripts\conda.exe info --json
Starting Pylance language server.
Python interpreter path: ~\AppData\Local\Programs\Python\Python38\python.exe
Error 2020-08-06 14:59:13: Attempted to download with skipDownload true.
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
Error 2020-08-06 14:59:16: Detection of Python Interpreter for Command py and args -2 failed as file Python 2 not found!
-3.8-64
-3.7-64 does not exist
Error 2020-08-06 14:59:16: Detection of Python Interpreter for Command py and args -3.6 failed as file Python 3.6 not found!
-3.8-64
-3.7-64 does not exist
> ~\anaconda3\Scripts\conda.exe info --json
> ~\anaconda3\Scripts\conda.exe env list
> ~\AppData\Local\Programs\Python\Python37\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py pip --version
Python interpreter path: ~\AppData\Local\Programs\Python\Python37\python.exe
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\el.mehdi.el.aouni\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\pyvsc-run-isolated.py pip --version
Editor support is inactive since language server is set to None.
Python interpreter path: ~\AppData\Local\Programs\Python\Python38\python.exe

There is an explanation here:
https://github.com/microsoft/vscode-python/issues/13327

Related

Build tensorflow: name 'json' is not defined

When building tensorflow from sources with bazel I have got error:
io_bazel_rules_go/go/private/sdk.bzl:337:12: name 'json' is not defined
How to add the dependency or import json library?
The code looks like python source, so I have tried to import json, which does not work.
clone tensorflow repo:
git clone https://github.com/tensorflow/tensorflow.git
configure
PYTHON_VERSION=python3.10
PYTHON_BIN_PATH=$(which $PYTHON_VERSION) \
PYTHON_LIB_PATH=$($PYTHON_VERSION -c "import pip; print(pip.__path__[0].rstrip('/pip'))") \
TF_NEED_CUDA=0 \
TF_NEED_ROCM=0 \
TF_DOWNLOAD_CLANG=0 \
CC_OPT_FLAGS="-march=native -Wno-sign-compare -mnoavx" \
TF_SET_ANDROID_WORKSPACE=0 \
TF_ENABLE_XLA=1 \
TF_NEED_OPENCL_SYCL=0 \
TF_NEED_MPI=0 \
./configure
and build
bazel build
My environment:
Ubuntu 22.04 LTS (all installed packages are up-to-date)
bazel 3.5.1- (#non-git)
tensorflow branch r2.11
As stated above, 3.5 is too old.
sudo dpkg -P bazel-bootstrap
sudo npm install -g #bazel/bazelisk

Exception: ERROR: Unrecognized fix style 'shake' is part of the RIGID package which is not enabled in this LAM

I'm trying to run a LAMMPS script in a Colab environment. However, whenever I try to use the fix command with arguments from the RIGID package the console gives me the same error.
I tested different installation and build methods, such as through apt repository and CMAKE:
Method 1
!add-apt-repository -y ppa:gladky-anton/lammps
!add-apt-repository -y ppa:openkim/latest
!apt update
!apt install -y lammps-stable
Method 2
!apt install -y cmake build-essential git ccache
!rm -rf lammps
!git clone -b release https://github.com/lammps/lammps.git mylammps
!rm -rf build
!mkdir build
!apt install -y fftw3
!cd build; cmake ../mylammps/cmake/presets/most.cmake -D CMAKE_INSTALL_PREFIX=/usr \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache -D BUILD_SHARED_LIBS=on\
-D PKG_GPU=on -D GPU_API=cuda -D LAMMPS_EXCEPTIONS=on -D PKG_BODY=on\
-D PKG_KSPACE=on -D PKG_MOLECULE=on -D PKG_MANYBODY=on -D PKG_ASPHERE=on\
-D PKG_EXTRA-MOLECULE=on -D PKG_KSPACE=on -D PKG_CG-DNA=on -D PKG_ATC=on\
-D PKG_ EXTRA-FIX=on -D PKG_FIX=on\
-D PKG_RIGID=on -D PKG_POEMS=on -D PKG_MACHDYN=on -D PKG_DPD-SMOOTH=on\
-D PKG_PYTHON=on ../mylammps/cmake
!cd build; make -j 2
!cd build; make install; make install-python
I also tested it by calling an external script using the file() method and writing commands to LAMMPS using the command() method.
The part of my code in the python script that returns an error is::
!pip install --user mpi4py
#!pip install lammps-cython
from mpi4py import MPI
from lammps import lammps
#from lammps import PyLammps
#from lammps import Lammps
import glob
from google.colab import files
from google.colab import drive
L = lammps()
...
L.command("fix freeze teflon setforce 0.0 0.0 0.0")
L.command("fix fSHAKE water shake 0.0001 10 0 b 1 a 1")
L.command("fix fRIGID RIG rigid molecule")
Or the same rows in LAMMPS script called:
#Using an external script
!pip install --user mpi4py
#!pip install lammps-cython
from mpi4py import MPI
from lammps import lammps
#from lammps import PyLammps
#from lammps import Lammps
import glob
from google.colab import files
from google.colab import drive
L = lammps()
...
L.file(input[0])
me = MPI.COMM_WORLD.Get_rank()
nprocs = MPI.COMM_WORLD.Get_size()
print("Proc %d out of %d procs has" % (me,nprocs),L)
MPI.Finalize()
The output error is:
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-60-a968719e9bc6> in <module>()
1 L = lammps()
----> 2 L.file(input[0])
3 me = MPI.COMM_WORLD.Get_rank()
4 nprocs = MPI.COMM_WORLD.Get_size()
5 print("Proc %d out of %d procs has" % (me,nprocs),L)
1 frames
/usr/local/lib/python3.7/site-packages/lammps/core.py in file(self, path)
559
560 with ExceptionCheck(self):
--> 561 self.lib.lammps_file(self.lmp, path)
562
563 # -------------------------------------------------------------------------
/usr/local/lib/python3.7/site-packages/lammps/core.py in __exit__(self, exc_type, exc_value, traceback)
47 def __exit__(self, exc_type, exc_value, traceback):
48 if self.lmp.has_exceptions and self.lmp.lib.lammps_has_error(self.lmp.lmp):
---> 49 raise self.lmp._lammps_exception
50
51 # -------------------------------------------------------------------------
Exception: ERROR: Unrecognized fix style 'shake' is part of the RIGID package which is not enabled in this LAM
Any suggestions what I can do?
You need to enable the RIGID package. For better flexibility on LAMMPS features it is better to build it from source code:
Download the latest stable version, and change the directory into it
git clone -b stable https://github.com/lammps/lammps.git mylammps
cd mylammps/src
Inclued all packes you need, obviously you need RIGID to use fix shake
make yes-rigid
Now you will need to build using MPI and share its library. This may take a while, you can add '-j N' flag to do it in parallel with N cores, I do it with 8
make mpi mode=shlib -j 8
Finally install Pylammps
make install-python
Now you should be able to use PyLammps through Colab successfully.

Tensorflow, TRT models installation problem

I installed tf_trt_models on Jetson-nano following the instructions here. I am getting the following error
Installed /home/tarik-dev/.local/lib/python3.6/site-packages/slim-0.1-py3.6.egg
Processing dependencies for slim==0.1
Finished processing dependencies for slim==0.1
~/tf_trt_models
Installing tf_trt_models
/home/tarik-dev/tf_trt_models
running install
Checking .pth file support in /home/tarik-dev/.local/lib/python3.6/site-packages/
/home/tarik-dev/.virtualenvs/nanocv/bin/python -E -c pass
TEST FAILED: /home/tarik-dev/.local/lib/python3.6/site-packages/ does NOT support .pth files
bad install directory or PYTHONPATH
Found the solution. In the install script, because I am in virtualenv, I will need to remove --user
Here is the install.sh script
#!/bin/bash
INSTALL_PROTOC=$PWD/scripts/install_protoc.sh
MODELS_DIR=$PWD/third_party/models
PYTHON=python
if [ $# -eq 1 ]; then
PYTHON=$1
fi
echo $PYTHON
# install protoc
echo "Downloading protoc"
source $INSTALL_PROTOC
PROTOC=$PWD/data/protoc/bin/protoc
# install tensorflow models
git submodule update --init
pushd $MODELS_DIR/research
echo $PWD
echo "Installing object detection library"
echo $PROTOC
$PROTOC object_detection/protos/*.proto --python_out=.
$PYTHON setup.py install --user
popd
pushd $MODELS_DIR/research/slim
echo $PWD
echo "Installing slim library"
$PYTHON setup.py install --user
popd
echo "Installing tf_trt_models"
echo $PWD
$PYTHON setup.py install --user

Error while installing numpy in alpine image

Error :
ERROR: Command "/usr/local/bin/python -u -c 'import setuptools, tokenize;file='"'"'/tmp/pip-install-2u_c2pqi/numpy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-gfsn5nsl/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-2u_c2pqi/numpy/
This is the error I am getting in my travis build of my dockerfile.
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
24 && apk --no-cache --update-cache add postgresql-dev musl-dev linux-headers g++ gfortran py-pip build-base bash libpng-dev openblas-dev w get freetype-dev gcc \
25 && ln -s /usr/include/locale.h /usr/include/xlocale.h \
26 && pip3 install setuptools wheel \
27 && pip3 install numpy pyyaml`
I am installing numpy using the above commands
Some issues have been found in your Dockerfile:
python3-dev and py3-pip packages should be installed to install numpy.
g++ already has gcc and musl-dev in dependencies, so we can simplify a package list.
The final Dockerfile is:
FROM alpine:latest
RUN echo "http://dl-8.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& apk --no-cache --update-cache add postgresql-dev g++ linux-headers gfortran build-base bash libpng-dev openblas-dev wget freetype-dev python3-dev py3-pip \
&& ln -s /usr/include/locale.h /usr/include/xlocale.h \
&& pip3 install setuptools wheel \
&& pip3 install numpy pyyaml

Building a .deb package of Mono itself

I'm currently compiling the latest version of Mono from Github on an original version Raspberry Pi, on latest Raspbian.
This is a very time consuming process, which when it's complete I would not like to have to repeat.
Can the compiled Mono installation be packaged into a .deb to, for example, allow me to re-install latest Raspbian, then dpkg -i my-mono-build.deb?
Sure, and it's very easy to do if you choose the proper tool so that you don't need a master on debian packaging. As for me, I chose fpm to do exactly this. (Note: install via gem, not apt-get.)
And here you have an example of a script of how to build a Mono .deb with this, which I copy+paste here for posterity (just in case I delete the github repo by mistake, or github stops being a thing in the future):
#!/bin/bash
set -e
die () {
echo >&2 "$#"
exit 1
}
[ "$#" -eq 1 ] || die "Please specify the version of Mono you want to build as the argument. (Check the versions in the tarball list here: http://download.mono-project.com/sources/mono/)"
which fpm > /dev/null || (echo "Please install fpm (from gem, not apt-get)" && exit 1)
if mono --version > /dev/null 2>&1; then
echo "Mono is installed locally; please uninstall first" && exit 1
fi
WORK_DIR=/tmp/7digital-mono-work
rm -rf $WORK_DIR
mkdir $WORK_DIR
cd $WORK_DIR
MONO_VERSION=$1
MONO_DIR="mono-$MONO_VERSION"
SEVEND_VERSION="701"
MONO7D_VERSION=$MONO_VERSION'.'$SEVEND_VERSION
MONO7D_NAME="mono-7d"
echo "Downloading $MONO_VERSION"
wget http://download.mono-project.com/sources/mono/mono-$MONO_VERSION.tar.bz2
tar -jxf mono-$MONO_VERSION.tar.bz2
TARGET_DIR="$WORK_DIR/destdir"
mkdir $TARGET_DIR
cd "$WORK_DIR/$MONO_DIR"
./configure --prefix=/usr
make
make install DESTDIR="$TARGET_DIR"
cd $WORK_DIR
fpm -s dir \
-t deb \
-n $MONO7D_NAME \
-v $MONO7D_VERSION \
-C $TARGET_DIR \
-d "libglib2.0-dev (>= 0)" \
usr/bin usr/lib usr/share usr/include usr/etc
echo "Done. Your package should be ready in $WORK_DIR"