Virtualenv not recognised in ipython Notebook Server - python

I have iPython running from a secured server on an Ubuntu server VM running on my laptop.
Command line ipython works on the server vm from the virtualenv. I can also start the notebook server on the server vm from the virtualenv without errors.
I can access notebooks from the host laptop and execute code in cells, but if I start the notebook server after activating a virtualenv I can't import any of the Python modules I've installed in the virtualenv.
It looks like the notebook server process is running the system Python but not the version in my virtualenv. Is there a way to tell the notebook server process which virtualenv to use?

Because virtualenv on activation adds its own ways to the begining of the PATH environment variable, you have two options:
a) create correct virtualenv on the notebook server and install everything from there
b) modify PYTHONPATH variable in order to get access to your libraries.

Related

Remote VSCode notebook looks for python on local machine path

I am having trouble with my vscode and ssh connection.
I have installed miniconda on my local machine at home/sam/miniconda3, and I have installed anaconda on a remote HPC machine on home/sam/anaconda3.
I have replicated conda envirenments in both using a yml file. Recently, the I keep getting errors while connecting to ssh that "python was not found". After digging for a while, I realize that when running a jupter nb, it looks for python under the local machine path (home/sam/miniconda3). Despite the case that I have selected the kernel from the remote machine path (/home/sam/anaconda3/envs/myenv/bin/python3.9).
How can I get the notebook in vscode to look at the remote path when connected to the remote machine?
Thanks heaps!

Cannot find python kernels corresponding to Virtual environment on remote

I am visual studio code Version: 1.63.2 (Universal).
I am connected to a linux server where my code is located (jupyter notebook). When i open the notebook and select the python kernel, i can only find the default python kernels (from the server). I cannot find the kernels that i created which is necessary to run the notebooks.
Note: The required kernel is linked to a virtual environment on the kernel.
Please help me in linking the remote kernel to my notebook on vscode so that i can work locally on the notebooks located in remote server.
I needed to install the python extension on the remote server.
You can find the answer in the second method here.
https://stackoverflow.com/a/62871909
I did a little differently:
Ctrl+Shift+P, Preferences: Open Remote Setting (SSH:your_address)
Set Python: Default Interpreter Path to your virtual environment Python path
Done
i've stumbled upon this post, since i had a similar issue.
working remotely on a linux server, even if i selected the right interpreter (via shift+ctrl+P "Select Interpreter to start Jupyter server") the kernel remained unactive.
i've checked the installed dependencies inside the venv and tried to switch virtual environment to make it work.. kept on reloading the server, reloading the window.. no way.
eventually, a tiny fancy detail arouse my attention: the "Jupyter server : remote" label in the bottom right.
and tadaa : that was my issue. I've selected "default", letting VSCode starting a server on the local (remote) host, and then the interpeter / kernel was enabled.
hope it can help anyone stuck on the same issue. jupyter server location detail

VSCODE how to debug python in conda environment in docker container in remote server

I start by enabling the docker container in the remote server, then I connect VSCODE to that server via SSH, and finally I attach VSCODE to the docker (docker extension installed).
I have selected the interpreter in the conda environment by editing a ./.vscode/launch.json file
When I start the python program debug the packages available in the conda environment are not visible to the python program.
What am I doing wrong?
thanks
You most likely need to select the Interpreter inside VSCode.
First open up the Command Palette Ctrl+Shift+P, then type Python: Select Interpreter then select the environment you want to use.

Anaconda Connect to Environment Created from Another Server

I have the following resources:
Server A with Anaconda installed at D:\Anaconda
Server B with Anaconda installed at D:\Anaconda
Network Attached Share mapped to drive E: on Server A and Server B
I created a conda environment on the NAS from Server A. Executing Python scripts from Server A within that environment works.
I would like Server B to be able to execute scripts against the environment on the NAS. The environment doesn't show up when running conda --info envs, because it wasn't created from Server B.
How do I use an environment on a NAS to execute scripts on a server that did not create the environment?
Add the directory above the environment to the conda config of server B. If the environment is at E:\conda\envs\shared_env use:
conda config --append envs_dirs E:\conda\envs
Given the information below, you need to do some testing from within both servers.
from conda.base.context import locate_prefix_by_name
locate_prefix_by_name('<environment name>')

Installing Anaconda on Server

I have a Unix server where I have Python3 installed. I ssh to the server from my mac.
I was wondering if it possible to install Anaconda and Jupyter (will come with Anaconda) on the server so that I can just pull up Jupyter on the server terminal and run codes on jupyter running on the server.
Is it possible? And if yes, could someone guide me to the right link?
in a terminal on your remote server:
#download anaconda (change version if you want)
wget https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh
# run the installer
bash Anaconda3-5.1.0-Linux-x86-64.sh
# so changes in your path take place in you current session:
source ~/.bashrc
#To run a remote notebook, replace XXXX with your choice of four numbers like 9191
jupyter notebook --no-browser --port=XXXX
#copy the url that you get as a result
Then in your local machine, open up a terminal and write:
#XXXX is the port you specified in the previous step, YYYY is a local port, for example 9999 to keep it simple
ssh -f [USER]#[SERVER] -L YYYY:localhost:XXXX -N
Then copy the url from the previous step, paste it in a browser, since you used the same port, you don't have to change anything on the url
you can download anaconda using:wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
and install using: bash Anaconda3-5.1.0-Linux-x86_64.sh
After that just source the path of Anaconda in .bashrc file, it should work.
To access jupyter notebook, you can use ssh and run notebook in your browser on your host. Steps are mentioned in this link
Yes you can install anaconda on your linux machine (Server) and manage the python environment. But if just need Jupyter hosted in a server, just install Jupyter only and start the service which will server Jupyter Notebook. Access Jupyter notebook using your browser on any other PC.
Make a google search that how to install anaconda on Linux machine (Centos/Ubuntu etc)
After installation run following command
conda info
and then configure the Jupyter and run.
Simple way (Install Jupyter on a server): Install, Run, and Connect to Jupyter Notebook on a Remote Server

Categories