I have a virtualenv activated through virtualenvwrapper but poetry is skipping and creating its own virtualenv - python-poetry

I have created a virtualenv in virtualenvwrapper with mkvirtualenv venv-quran-srs-375 -p python3.7 and activated it. Then switched into the project directory and ran poetry init and specified python3.7.5 as the dependecy as doing python -V inside the virtualenv shows me 3.7.5.
Then I executed poetry add Django and I get this message that it is creating the venv since the activated version is 3.8.5 (which is the version that conda has).
The currently activated Python version 3.8.5 is not supported by the project (3.7.5).
Trying to find and use a compatible version.
Using python3 (3.7.5)
Creating virtualenv quran-srs-ALPX3iit-py3.7 in /Users/siraj/Library/Caches/pypoetry/virtualenvs
Using version ^3.2.8 for Django
I am fairly new to the python world - so, I am not sure whether there is a conflict here between conda and virtualenvwrapper. I even installed pyenv and did pyenv local 3.7.5 before running poetry init, as specified in the docs. But it is not using the env I have created. Can someone help me figure out the problem here...
here is a pretty-print of my path when I am inside the activated virtualenv.
/Users/siraj/.virtualenvs/venv-quran-srs-375/bin
/Users/siraj/.pyenv/shims
/Users/siraj/.local/bin
/Users/siraj/.nvm/versions/node/v16.3.0/bin
/opt/anaconda3/bin
/opt/anaconda3/condabin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
and pyenv versions gives this output - I guess here system refers to 3.8.5 installed by conda
system
* 3.7.5 (set by /Users/siraj/Projects/quran-srs/.python-version)
3.9.5

Related

Cannot install python wheel file in conda without sudo

I'm trying to build PyTorch from a .whl file on a jetson nano.
I am able to build and install the file but only while using sudo, attempting to pip install the file without sudo results in this error:
ERROR: torch-1.10.0a0+git36449ea-cp36-cp36m-linux_aarch64.whl is not a supported wheel on this platform.
This is strange as with admin I have no issues installing this file, but I can then only use the library by using the sudo command before going into or running with the python command.
I should note that this is in a conda environment, but even in the base conda environment this issue still occurs.
It seems like I can also install the package by using conda deactivate to deactivate conda.
I am using Python 3.7 in the conda environment and Python 3.6 outside.
I am using Python 3.7 in the conda environment and Python 3.6 outside.
This is the issue. You have a cp36 whl file, so python 3.6. I am suspecting that when you run sudo pip, your systems pip is invoked, whereas when you run pip, then pip from your conda env is used, and cannot install a python 3.6 whl to a python 3.7 env.
Either you need to get the cp37 whl or create a conda env that has python 3.6 installed

conda environment broken after updating conda

after using conda extensively for a while, I was asked to update it yesterday and now things look broken. I have to admit that I am not an expert of what goes on behind the scenes so bear with me :)
After installing conda I used pip to install the various packages.
Yesterday I started working on some code from a tutorial on git, which suggested to create an ad-hoc environment to work with:
conda env create -f binder/environment.yml
At this step I was suggested to update conda, since I was using an old version. I can't find in my terminal that specific message (i.e. I can't find what version of conda I was using before), but here is what I get now when I check the version of conda:
(base) francesco ~$ conda list conda
# packages in environment at /Users/francesco/anaconda3:
#
# Name Version Build Channel
_anaconda_depends 2019.03 py36_0
anaconda custom py36_1
anaconda-client 1.7.2 py36_0
anaconda-navigator 1.8.7 py36_0
anaconda-project 0.8.4 py_0
conda 4.8.3 py36_0
conda-build 3.10.5 py36_0
conda-env 2.6.0 h36134e3_0
conda-package-handling 1.6.0 py36h1de35cc_0
conda-verify 3.4.2 py_1
One of the things I noticed after the update is that in order to activate/deactivate the environment I had to use conda activate/deactivate <env> instead of source activate/deactivate <env>.
After that I worked with the code in the new environment without any problem.
Today I tried to activate the main environment I work with, but I was asked to "init" my shell first with:
conda init bash
After that I activated my "usual" environment:
conda activate testenv
and I tried to start Jupyter Lab, but I got this error:
(testenv) francesco ~$ jupyter lab
Error executing Jupyter command 'lab': [Errno 2] No such file or directory
What is happening? Why is Jupyter Lab not working anymore in my usual environment?
I checked the installation in testenv and things look ok:
(testenv) francesco ~$ conda list | grep jup
jupyter 1.0.0 py37_7
jupyter_client 5.2.4 py37_0
jupyter_console 6.0.0 py37_0
jupyter_core 4.4.0 py37_0
(testenv) francesco ~$ pip list | grep jup
jupyter 1.0.0
jupyter-client 5.2.4
jupyter-console 6.0.0
jupyter-core 4.4.0
(testenv) francesco ~$
Does anyone know what is going on? This is a huge problem for me as conda/jupyter lab are the main tools I use for work :\
The common practice is to only install Jupyter in a single Conda environment (typically your base env if an Anaconda user), and always launch Jupyter from there. To use other Python envs in Jupyter, you need to install ipykernel in those envs, e.g.,
conda install -n testenv ipykernel
And, to avoid having to register your additional envs, it is recommended to install nb_conda_kernels in the env with Jupyter, e.g.,
conda install -n base nb_conda_kernels
As a side note, installing things with Pip can make environments unstable. I strongly recommend learning and adhering to the documented best practices.
#FrancescoLS It seems that you had perhaps an older version of Conda installed(?) as the CHANGELOG indicates that source activate was deprecated in favor of conda activate in Conda v4.4.0 (as is also noted in this "How to Get Ready for the Release of conda 4.4" post from Anaconda).
This really isn't an "answer" in any actionable way, but it seems that you are not alone in Conda update breaking people's environments.
superuser: Conda update conda does extra stuff and destroy my anaconda install
Conda Issue #8842: Conda Deletes All Modules During Update
there are lots more. :/
I think it is safe to say that keeping virtual environments safely intact during an upgrade is hard to do, and that when doing a major upgrade across virtual environment maintainers (Conda) it is even harder. This is one of the reasons that I personally try to have all of my project virtual environments be maintained either in native Python 3 venv virtual environments with pip or through Poetry (as they are (or at least used to be) way faster to restore than having to go through Conda's slower solver) and then only resorting to using Conda when I need to bring in multiple external binary applications.
Were you able to make a new Conda environment for your work that effectively restores it (perhaps from your own environment.yml file for that environment)?

Dependency issue with conda, pip and virtualenv

I am using conda(anaconda 2). Before installing anaconda, my Ubuntu16.04 already had pip installed. I recently installed virtualenv using pip install virtualenv. I did the following steps while trying to install coala in my virtual environment.
Create a new virtual environment using virtualenv venv
Activate environment using source activate path/to/activate
Clone the coala repository.
Run pip3 install -e . while inside the repository
After all this, I get the following error from coala:
There is a conflict in the version of a dependency you have installed and the requirements of coala. This may be resolved by creating a separate virtual environment for coala or running `pip install "yapf~=0.14.0"`. Be aware that the latter solution might break other python packages that depend on the currently installed version.
I am already in a virtualenv, so I tried installing yapf as per the command: pip install "yapf~=0.14.0". After that, when I check my pip list, it still showed yapf (0.15.2), To solve this, I did:
pip uninstall yapf
pip install "yapf~=0.14.0"
Now when I check my pip list, I get the desired results. BUT, the error is still there. It still shows the same dependency error. I am unable to understand what is happening? Which pip is installing what and where, what is conda doing behind the scenes, how is virtualenv behaving with conda, and the most important, why this error and how to resolve it?
first create a virtualenv pertaining to python3.x
template
virtualenv -p {location of python3 version } {name of virtualenv folder}
like this
virtualenv -p /usr/local/bin/python3 venv
then activate it
source venv/bin/activate
then run
pip install {library you want to use}
pip install "yapf~=0.14.0"
This should install yapf into the venv folder.
try that let us know.
Answering my own question, what I found out was that conda and virtualenv do not go hand in hand. condas has the ability to create it's own virtual environment, and if using condas, we must create a conda virtual environment(See this answer).
What I did was uninstalled conda and make a virtual environment using virtualenv. What I could have done as well is uninstall virtualenv and create condas environment and work in that.

Can't update anaconda and python 3.6

I have Anaconda Python=2.7, and I try to install Anaconda Python 3.x
but it says I just need to update the using conda update python=3.6
and I do this:
$conda update anaconda
but the result always:
PackageNotFoundError: Package not found: 'anaconda' Package 'anaconda' is not installed in /Users/MacBook/miniconda3
I successfully installed python 3.6 from python website, but when I check with:
$python --version
The result is Python 2.7.12 and when I try:
$conda install python=3.6
or:
conda create -n py36 python=3.6 ipykernel
the result is:
CondaHTTPError: HTTP 404 None
for url <None>
The remote server could not find the channel you requested.
You will need to adjust your conda configuration to proceed.
Use `conda config --show` to view your configuration's current state.
Further configuration help can be found at <http://conda.pydata.org/docs/config.html>
The reason I am doing this is because I want to have an option for python version in Jupyter notebook.
but when I do
$ which -a python python=3.6
/Users/MacBook/miniconda3/bin/python
/Users/MacBook/miniconda2/bin/python
/Users/MacBook/anaconda/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python
I do same on my mac mini, and it works fine.
Have I messed up my python folder ?
I have Anaconda Python=2.7, and I try to install Anaconda Python 3.x but it says I just need to update the using conda update python=3.6
and I do this:
$conda update anaconda
but the result always:
PackageNotFoundError: Package not found: 'anaconda' Package 'anaconda' is not installed in /Users/MacBook/miniconda3
This seems to me that your Anaconda (and thus Conda) wasn't properly installed. You should be able to download the Anaconda package and install it in one click. After that I would test if conda is working properly by running conda list and conda search.
I successfully installed python 3.6 from python website, but when I check with:
$python --version
The result is Python 2.7.12 and when I try:
The reason is most likely because python 3.6 is not in your PATH. Try echo $PYTHONPATH and echo $PATH.
$conda install python=3.6
or:
If you wish to use only python 3.6, this is how you can install it.
conda create -n py36 python=3.6 ipykernel
the result is:
if you wish to have both python 2 and 3, this is how you'd install python3.
I would do conda create -n py36 python=3.6 anaconda ipython
CondaHTTPError: HTTP 404 None
for url
The remote server could not find the channel you requested.
You will need to adjust your conda configuration to proceed.
Use conda config --show to view your configuration's current state.
Can you paste what you see after executing conda config --show?
do you see something like
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: True
channels:
defaults
client_ssl_cert: None
client_ssl_cert_key: None
clobber: False
create_default_packages: []
custom_channels:
pkgs/r: https://repo.continuum.io/
Users/admin/anaconda/conda-bld: file:///
pkgs/pro: https://repo.continuum.io/
pkgs/free: https://repo.continuum.io/
custom_multichannels:
local: ["file:///Users/admin/anaconda/conda-bld"]
defaults: ["https://repo.continuum.io/pkgs/free",
"https://repo.continuum.io/pkgs/r", "https://repo.continuum.io/pkgs/pro"]
default_channels:
https://repo.continuum.io/pkgs/free
https://repo.continuum.io/pkgs/r
https://repo.continuum.io/pkgs/pro
but when I do
$ which -a python python=3.6
/Users/MacBook/miniconda3/bin/python
/Users/MacBook/miniconda2/bin/python
/Users/MacBook/anaconda/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python
look at you PATH and PYTHONPATH.

How can I install an older version of boto on an AWS instance?

We have multiple Ubuntu instances on AWS EC2 with different versions of boto installed. One has 2.2.2, the other 2.8.0. One of our script behaves differently on the two machines, not working on the one with the older boto. I am trying to see if the version difference is the reason for it, or if there is something else going on. So what I want to do is to go back to 2.2.2 on the instance with 2.8.0 to test. How do I install an older version? I tried sudo pip install -U boto 2.2.2 but it gave me Could not find any downloads that satisfy the requirement 2.2.2
I would use virtualenv. Create a new virtual environment on the instance with 2.8.0 and make sure that you tell virtualenv not to use the system-installed packages. I'm pretty sure that is the default behavior but, just in case:
$ virtualenv --no-site-packages test_old_boto
Once the virtualenv is created:
$ cd test_old_boto
$ source bin/activate
and then install the old version of boto in the virtualenv:
$ pip install boto=2.2.2
and you should the be able to test things out.
as Lisa Watanabe correctly answered and for whatever reason deleted, the correct syntax is sudo pip install --upgrade boto==2.2.2 or pip install --user --upgrade boto==2.2.2

Resources