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

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.

Related

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.

i install conda installed and Python installed seperately

i have Conda installed and Python installed separately, when i run .py file it is referencing to python's packages not from Conda so some pkg are missing(pandas), Conda has pandas but not Python. all default installations are go to Conda pkg files. how do i install pandas to Python that is not in Conda?
To run a file from conda, simply go to your anaconda prompt and cd into the drive. Similarly, you can search for your python prompt from the start bar and run code from there.
To install pandas into your python installation type:
pip install pandas
If you are running code from an IDE or code editor, you need to go into your settings and change the default runtime environment to anaconda. Even easier, open your anaconda navigator and then run your editor from there.
Your conda installation can't not have python, although it might be running the wrong version of python for your code. To change the version of python type:
conda install python=$pythonversion$
into your conda prompt.

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.

IPython Notebook - python3 not found after uninstalling Anaconda3 for Anaconda

I uninstalled Anaconda 2.3 with Python 3.4.3 and then installed the same Anaconda version with Python 2.7.10.
When I open a notebook via $ ipython notebook "Example Notebook.ipynb" it tries to use the python3 kernel as opposed to opening with the installed python2. Of course I get the error python3 kernel not found.
How can I get ipython notebooks to open with the python2 kernel? I've tried to uninstall ipython and ipython notebook, then delete .ipython and .jupyter from my user directory in case there were any defaults set in these folders, then reinstalled both. Still get the same problem.
Any help would be appreciated
You can install several python versions alongside each other. Just create another environment (replace "all my packages" with the names of the packages).
conda create --name mypy_27 python = 2.7
or
conda create --name mypy_34 python = 3.4
afterwards you can activate the environments by typing
source activate mypy_34
if you then do
conda install "all your packages"
you install the desired packages in the active environment.
You can do much more.

Categories