conda environment has been broken after installing an application - python

I am using Macbook M1 and I have installed Python using Miniforge/Conda. So virtual environment has been created, Python has been succesfully installed as well as pandas, numpy and other modules. I run some simple script with import pandas. After that I have installed TDSR, it is a screen editor for blind users, suitable for Mac Terminal.
https://github.com/tspivey/tdsr
I've cloned the repository of TDSR, then run some pip3 installation, as written in the readme of TDSR.
Every step I've done in the virtual conda environment in my home directory. But after pip3 install command the virtual environment disappeared and the Python script I've previously run cannot find pandas module. Is there any way everything can be restored?
Thanks
Jan

Related

Virtualenv seems to be active but really don't on MAC

I have a virtualenv called env on my directory...After activating:
source env/bin/activate
I see that it is activated...(env)
I have installed some libraries on the virtual env, and i can see that they ares installed on their folders, but calling...
pip list
The libraries that Appears on the list are not the libraries installed on the env.
Also calling a python file to execute, dontn run.
Therefore calling for checking the python version, don't match with the env python version.
I have tried to reinstall python and pip, but nothing happens
I work on a 2 macOS machines and I use iCloud for sharing my projects. I created the env on one macOS machine but the same env didn't work on the other macOS machine. That was the problem.
I created a requirements.txt on the first macOS machine, then I created a new env on the other macOS machine, loaded the requirements.txt, and it now works.

import package from my Pycharm project and not from my conda environment

I am working on a python project in Pycharm. Lately I have created a setup.py in order for collaborators to be able to install and test the project on their systems. To test that everything is working fine, I have also installed it in my conda environment, which is the same as used by the interpreter in my Pycharm project. Now when I import my package in Pycharm it gets imported from the conda environment and not from my Pycharm project. Is there a way to tell Pycharm to look first in the Pycharm project subdirectories and then in the conda environment? Or do I need to uninstall my package from the conda environment that I use in Pycharm?
The proper way to go is to first create a virtual environment and then install your package in editable mode along with its required dependencies, as specified in setup.cfg.
Step 1: Activate your virtual environment
source /path/to/your/venv/bin/activate
or
conda activate vevnName
Step 2: Install your package in editable mode
pip3 install -e .
This command is going to install your package and link it to the original location (i.e the one that probably you want to be editing in PyCharm) so that any change being made is also replicated on your venv.
You can now open your Python application on PyCharm, from its original location and any changes you make in your IDE will be reflected directly on your virtual environment.

Downloaded module with Anaconda, but it's not found in Pycharm environment

I successfully downloaded 'geohash' module using Anaconda. I confirmed it works by testing a line of code in Jupyter notebook. However, in Pycharm, it cannot find the geohash module.
I see the module 'geohash' clearly is in my Anaconda site-packages folder.
I then opened a new python file in Pycharm, and selected "New Conda Environment" as the Project interpreter. You can see the file's interpreter is Anaconda Project Default (Python 3.7) :
And yet, there is no 'geohash' module in the venv in Pycharm, and the module cannot be found:
I'm confused as to why this is so. I would assume all my modules installed with Anaconda would transfer over once the project interpreter is set to Anaconda Python 3.7. What am I doing wrong?
When creating a new environment with conda, only the default packages are installed at the beginning. When you created the Geohash environments, it was created with only the default packages conda comes with, and geohash is not a part of that.
You would need to install the geohash package to your particular environment using:
# Install pip in your environment
conda install -n GeoHash pip
# activate your environment
conda activate GeoHash
# Install the package
pip install Geohash
you can read more about managing environments here
I don't know which version of PyCharm you are using. I think you should choose to use existing environment and point to the environment (could be the conda default) where you installed the package. IIUC, choosing "New Environment" would create a new conda environment which does not have your package.

problems creating virtualenv when installing two different versions of Python

I have installed Python 2.7, pip and virtualenv on my computer and I have created a virtual environment with this same version of Python. I installed some packages in this new virtual environment too.
Later, I decided to install Python 3.6 on the same computer to create a virtual environment that works with version 3.6. I downloaded Python 3.6 and installed it by selecting Add Python 3.6 to PATH and Install for All users and I selected the option to automatically install pip. As I had previously installed virtualenv, I have not had to reinstall it. Should I?
The problem is that, once installed, when creating a virtual environment I've got an error.
As I already had a version of Python installed I have specified that I want to use Python 3.6 in the virtual environment that I am creating:
virtualenv env2_py36 -p c: \ Python36 \ python.exe
The error already says that this usually happens when you install more than one version of Python on the same computer and warns that it is necessary to check the option Install for All Users to work (as I did) and also recommends placing the appropiate PythonXX.dll file in the Scripts folder of the virtual environment. However, I see that there is already a python36.dll file there.
Could anybody tell me what should I do to fix this problem?
On the other hand, I had previously created another virtual environment using Python 2.7. I use PyScripter to run my scripts but I don't know how to connect PyScripter to my virtual environment. It's still connected to the Python2.7's system installation.
This works for me:
virtualenv --python=python3.6 yourenvname
(3.6 is the current latest version of Python, but you can use whichever version you'd like.)

when I pip install, my packages are going in my macs local library

when I pip install a package it gets insalled on my macs library. I am using pycharm whih allows me to click on a package like a hyperlink. And instead of going to my site-packages in my virtualenv it's going to my macs library which is
/Library/Frameworks/Python.Framework/Versions/3.5/lib/python3.5/site-packages/gdata/youtube/
when it should be
myproject/lib/python3.5/site-packages/gdata/youtube/
why is that.
You should activate your virtual environment to install packages on that. In Pycharm you can do it like this:
Go to File > Settings > Project > Project Interpreter
Now you have to select the interpreter for this project. Browse or select the interpreter from drop-down if available. In your case this should be:
myproject/lib/python3.5
I am using Pycharm community edition on Ubuntu. But the
process should be similar in Mac.
I think you want to create a virtual environment for your project.
Install this tool virtualenv.
$ pip install virtualenv
Then create your project's folder
$ cd my_project_folder
$ virtualenv venv
This creates a copy of Python in whichever directory you ran the command in, placing it in a folder named venv.
Source
https://github.com/pypa/virtualenv
For further knowledge read
https://realpython.com/blog/python/python-virtual-environments-a-primer/
You should install your virtual environment and then run pip within that environment. So, for example, I use Anaconda (which I thoroughly recommend if you are installing alot of scientific libraries).
To activate the environment "hle" I type in:
source /Users/admin/.conda/envs/hle/bin/activate hle
Once I've done this the pip command will reference the virtual environment location and not the standard mac location. So, when I install "mypackage" as follows:
pip install mypackage
It subsequently installs files in the virtual folder and not in the usual mac system folders.
You can find out about the Anaconda virtual environment (and download it) over here: http://conda.pydata.org/docs/install/quick.html but other virtual environments (like Virtualenv) work in the same way.

Categories