making virtual environment with venv in python - python-venv

I am building a data analysis pipeline in which I need to create a virtual environment using this command:
python3 -m venv venv
And then I will activate it using:
source venv/bin/activate
I have 2 questions:
1- would it be fine to call the venv also venv? In fact would it make problem if I have 2 venv in the same command?
2- in the manual page it is mentioned that after the activation of virtual environment, “you can confirm you’re in the virtual environment by checking the location of your Python interpreter” using this command: “which python “. Does it have any advantage to add it to my pipeline?

Related

RASA : ModuleNotFoundError: No module named 'wikipedia'

I'm learning to use rasa language. To diversify the answers of the goal I decided to use the Wikipedia api. To create my working environment I used anaconda with the following commands:
conda create --name rasaWiki python == 3.7.6
conda activate rasaWiki
pip install rasa
pip install wikipedia
In the action.py file, when I try to import 'wikipedia', and launch the server with the command: rasa run actions I get the error:
ModuleNotFoundError: No module named wikipedia
However, I can compile other python programs that use the wikipedia package with the python command python 'nameOfTheFile.py'.
I managed to solve the problem. I work under windows, I use anaconda prompt 3. When I was running the rasa run actions command, I was in the environment (base). The wikipedia package I had installed is in the rasaWiki environment. So I installed Wikipedia with the command pip install wikipedia in the (base) environment, which solved the problem.

import tensorflow working in terminal but not in jupyter notebook

I used the following guide to install tensorflow-gpu - https://towardsdatascience.com/tensorflow-gpu-installation-made-easy-use-conda-instead-of-pip-52e5249374bc
I created a new environment and installed tensorflow-gpu using the command -
conda create --name tf_gpu tensorflow-gpu
If I activate the environment, start python in terminal, and import tensorflow from the terminal, it works.
BUT
When I activate the environment, run a jupyter notebook and type -
import tensorflow
I get module not found error. How do I resolve this?
Start Command Promt (CMD) as administrator (right click). Do not enter any environment yet.
Install Jupyter (and nb_conda as well as ipykernel) to get your environments listed: conda install jupyter nb_conda ipykernel
Activate the environment you want to add to jupyter kernel: conda activate myenv
Install ipykernel in the environment (do this for all envvironemnts you would like to add): conda install ipykernel
To start Jupyter, cd to root (cd .. until you are at C:) then type (does not need to be inside and env): Jupyter noteboook
You might need to confirm that it shall open in a web browser (I use chrome)
Once open in a browser navigate to the folder of your choice, then make a new python 3 file.
Once inside click Kernel -> Change kernel and select the conda env you would like
You should now be able to change kernel (env) within all conda environments that have ipykernel installed (step 4)

Is there a way to use Python 3.5 instead of 3.6?

I need to install a library that is only compatible with Python 3.5. Is there a way to change the Python version in Colaboratory from 3.6 to 3.5?
The only way to vary the Python 3 version is to connect to a local runtime.
You cannot directly change the environment for the notebook.
After hours of exploration, I found a solution:
Initialize a Ngork server in the Colaboratory notebook.
connect to the Ngork server from a local terminal using SSH (or use any editor which supports SSH connections)
Install the required Python version using the terminal.
Install virtualenv.
Create a virtual environment by specifying the Python version installed.
Activate the environment.
Work in that environment from the terminal directly.
Check out Free!! GPUs on your local machine which provides to get detailed description on how to follow the steps.
There is a way to use any version of python you want 3.5 or 3.8 in this example, without having to run a kernel locally or going through an ngrok proxy.
Download the colab notebook. Open a text editor to change the kernel specification to:
"kernelspec": {
"name": "py38",
"display_name": "Python 3.8"
}
This is the same trick as the one used with Javascript, Java, and Golang.
Then upload the edited notebook to Google Drive. Open the notebook in Google Colab. It cannot find the py38 kernel, so it use normal python3 kernel.
You need to install a python 3.8, the google-colab package and the ipykernel under the name you defined above: "py38":
!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh
!chmod +x mini.sh
!bash ./mini.sh -b -f -p /usr/local
!conda install -q -y jupyter
!conda install -q -y google-colab -c conda-forge
!python -m ipykernel install --name "py38" --user
Reload the page, and voilà, you can test the version is correct:
import sys
print("User Current Version:-", sys.version)
A working example can be found there.

How to install tensorflow with Conda

I have been trying to install tensorflow via Conda for a couple days now with no luck.
I made a fresh install of anaconda3/miniconda3 followed the steps to fix the .bash_profile issue. Then
$ conda create -n tensorflow pip python=3.6
seems to work. However
$ source activate tensorflow
does nothing. I tried conda activate tensorflow and nothing. If I type conda info I can see that the tensorflow env is running. But I have no ability to type within it?
Welcome to Python and Tensorflow.
This bit really takes a long time to figure out unless somebody told you how to do so.
Follow this. Assume you installed Miniconda (then python is automatically installed) and you are using linux (cuz you mentioned 'source')
You want to make an conda environment named 'ai3' and you wanna install many packages like tensorflow within 'ai3' env.
In your command line,
1) Create ai3 env: see https://conda.io/docs/user-guide/tasks/manage-environments.html for details
$ conda create -n ai3 python=3.6
2) Log your current command window into the ai3 env
$ source activate ai3
3) Install packages, for example tensorflow: details in https://www.tensorflow.org/install/install_linux but that does not really help FOBs
$ pip install tensorflow
4) Enter yes whenever your command window asks sth. Once it's done, then you wish to use tensorflow (TF) in python. Do this
$ python
$ >> import tensorflow as tf
$ >> hello = tf.constant('Hello, TensorFlow!')
$ >> with tf.Session() as sess:
$ >> sess.run(hello)
4-1-0) Obviously you don't wanna do this all the time. Download Pycharm community edition (in https://www.jetbrains.com/pycharm/download/#section=linux) and install.
4-1-1) Create a new project in any location you like with interpreter 'ai3'. Interpreter is the env you just prepared in step 1,2,3): click 'add local' by clicking a button at the right end of the 'Interpreter' line -> a python file at '/miniconda3/envs/ai3/bin/python'
5) Now work with many tutorials out there on this setup
First you need to check the naming convention you are using. I know that's how documentation suggests, but I think it's misleading.
Name your environment according to what you want to be doing inside of it. Tensorflow is a package (that can be a python package) that you will use inside of the environment so you can name it something like:
$ conda create --name 'machinelearning-env' pip python=3.6
Also if you just installed Anaconda you do not need to specify the python designation.
Then you need to activate your environment with
source activate (whatever you named your conda env)
Next you can install with :
:~/anaconda3/envs$ pip install --ignore-installed --upgrade (the tensorflow url found here: https://www.tensorflow.org/install/install_linux#the_url_of_the_tensorflow_python_package )
Finally instantiate python and then you can import tensorflow with :
import tensorflow as tf
I suggest you refer back to the tensorflow documentation as it's all there. Good luck!
You should first give a name to your environment then give package names that you want to install ie.
conda create -n tensorflow_env tensorflow
Easiest way for me at least.

What python virtual environment install locally and system-wise?

When Python virtual environment venv is activated, I wonder what installation will be added to the local venv and what go to the OS as system-wise?
I ask after notice that my LAMP installation, while venv is activated, has the system-wise effect i.e. NOT within the environment as I thought.