I try to use virtualenv inside a folder using the command virtualenv . and getting the error -bash: virtualenv: command not found. However, I installed virtualenv using pip pip installed virtualenv and also, upgraded it earlier with sudo pip install virtualenv.
How to use virtualenv properly ? I'm following a tutorial and they seems doing the same and gets away with it. I'm a Java developer with beginner knowledge of Python and working to improve it.
This is pretty simpleJust goto environment folder
Try: Scripts/activate
This will activate the environment
Try:Scripts/deactivate
This will deactivate current environment
Related
I try using pip and pip3 and python -m pip and all ways to install. The terminal says the packages already installed after the first try to install, but when I try to import the package I had error no moudel name.
I feel the peoblem coming form here
But I am not sure
And when I go to packages in pycharm I saw the packages not installed
I appreciate your help
I'm assuming you're using windows.
It looks like you install the package directly in your system and PyCharm are using a virtual environment to run your code.
Try to activate this virtual environment before run your code:
source venv\Scripts\activate
If you see "(venv)" at the begging of your terminal prompt the virtual environment are activated.
Run pip list to check what packages are installed in there and probably you have to install your package another time, this time in your activated virtual environment. The official documentation will help to understand how and why use virtual environments.
After that you can try to run your code directly from the terminal:
python your_file.py
Install the packages from PyCharm itself, not the terminal as I think pycharm is running a virtual environment.
Maybe you can follow https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#packages-tool-window
I know there are some similar questions,but it is really hard for me to finish it.
I'm trying to create a virtualenv with python 3.7.7 in windows.
I have a downloaded python 3.7.7
C:\Users\willi\AppData\Local\Programs\Python\python-3.7.8-embed-amd64
Since I can built a virtualenv using:
python3 -m venv myenv
So I tried to modify it ,so that it can match specific python version:
python3 -m C:\Users\willi\AppData\Local\Programs\Python\python-3.7.8-embed-amd64\python.exe myenv
But it failed:
ModuleNotFoundError: No module named 'C:\\Users\\willi\\AppData\\Local\\Programs\\Python\\python-3')
Any friends can teach me how to build a virtualenv with python 3.7.7?
I think you haven't installed virtual environment in your local python
pip install virtualenv
and follow your steps. Stil, find the error. Try doing below methods, I think you will get your answer-
in command prompt
pip install virtualenv
go to the location, where you want to create your environment
cd location
virtualenv project_env_name
Now, you will find a python env in the desired location, Then go to scripts
cd project_env_name/scripts
activate
You will enter the environment you created. while leaving the environment, do
deactivate
To leave the environment.
This method works if you want to create the same python version environment as python version in your machine.
If you want to create an environment of the different version, you need to install the python of that version.
I am trying to install numpy, nltk, etc packages for Python 2 to run a code. But I have Python3 as well and the path variable is set to it. When I try to use any pip install command it shows the package is available in Python3's directory.
Also, I am using VSCode, so I did not add the path variable.
I suggest you use virtual environments. Because if you read about virtual environments, you will find that they are created for such cases.
To create virtual environments, you must do the following:
Make a note of the full file path to the custom version of Python you just installed.
virtualenv -p /home/username/opt/python-2.7.15/bin/python venv
In order to use this environment’s packages/resources in isolation, you need to “activate” it. To do this, just run the following:
source venv/bin/activate (Linux)
./venv/Scripts/activate.bat (Windows)
Notice how your prompt is now prefixed with the name of your environment (venv, in our case). This is the indicator that venv is currently active, which means the python executable will only use this environment’s packages and settings.
Now run the following:
(venv) $ which python
/Users/ashkan/python-virtual-environments/venv/bin/python (in my case)
now you have access to python2.7.
The best practice for this particular problem would be virtual environments.And for that matter Pipenv would be a good option.
Install Pipenv.
$ brew install pipenv (MacOs)
$ sudo apt install pipenv (Debian)
$ sudo dnf install pipenv (Fedora)
pip install pipenv (Windows)
Creating virtual env with Pipenv.
pipenv install --python 2.7 numpy
This command will install create a virtual environment and install python 2.7(which will be used as the main interpreter once you activate the environment) along with numpy in that environment. This will avoid the packages version conflicts too.
To activate the environment
pipenv shell
If you are working in the Vs Code workspace then you should set the interpreter path(python path) to the path of the virtual environment.
when we install anything using pip. it will install dependencies for default python version. so you can change the default python version using this link https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Hope this will solve your problem
After crating a virtual environment with python 2.7 you can install your required packages
I am trying to create a new virtual environment for a tutorial. I have installed virtualenv and virtualenvwrapper multiple times but every time I try creating a new virtual environment my terminal displays - mkvirtualenv: command not found. When I try finding out the version of virtualenv it shows virtualenv: command not found. Something similar was happening with my pip installation as well but then it got resolved when I used some command.
I would like to point out that my PATH seems to be really messed up. The PATH is pointing to /Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin. Please help.
I saw something else when I use pip show virtualenv it gives me details of the version and the author but when I use virtualenv --version it sends a virtualenv: command not found.
First of all, you will need to install virtualenv as it is a python 2 external dependency.
pip install virtualenv
this will allow you to use virtualenv globally.
Alternatively, you can use from Python 3.5+
python -m virtualenv venv
However if you dont wish to support python 2 you can use venv which is installed on from python 3.3
python3 -v venv venv
Took quite some time to figure it out but what worked for me was to install it using pip3 install instead of pip install
pip3 install virtualenv
I made sure to read this question and similar ones, but I couldn't find an answer to my problems.
My problem is: when I head into muy virtual env and activate it, if I install a package there, it is also installed elsewhere in my computer.
So, for example, if I type in the terminal:
cd home/Documents/Python/tests/my_virtual_env
source bin/activate
That activates the virtual environment. If I type:
pip3 install wget #just an example package
I see the installation process and I can run a .py script that uses wget. However, why is this package also installed elsewhere in my computer?
I made sure I hadn't that package installed beforehand using pip3 list.
I confirmed that package was installed elsewhere by running a .py script from other directories (using cd /etc.etc/ to change directory and then running it from there).
I deactivated the environment in the right moment.
I also realized that if I uninstall that package within the virtualenv, it is also uninstalled elsewhere.
Thank you so much for your help.
It could be that the pip3 command being executed is not actually tied to the virtual environment. So instead you could the following, which would work whether or not the virtual environment is activated:
$ path/to/my_virtual_env/bin/python3 -m pip install SomeProject
The following command should give you a relatively clear indication of where exactly the project has been installed, make sure it is in the site-packages directory of the virtual environment:
$ path/to/my_virtual_env/bin/python3 -m pip show SomeProject
So it should show something of the sort:
Name: SomeProject
...
Location: .../path/to/my_virtual_env/lib.python3.X/site-packages
However, why is this package also installed elsewhere in my computer?
The following shows where a binary is located:
$ which somecommand
It should be relatively easy to recognize if somecommand is in a Python virtual environment or not.