How Pycharm is related to Anaconda and Python? - python

I am getting an error while installing the package
pyramid-arima
I tried the following but could not resolve the issue
conda create -n pmdissue23 --yes --quiet python=3.5 numpy scipy
scikit-learn statsmodels
activate pmdissue23
pip install pyramid-arima
Output of above commands:
Requirement already satisfied: scipy>=0.9 in
/anaconda/envs/pmdissue23/lib/python3.5/site-packages (from pyramid-
arima)
Installing collected packages: Cython, pyramid-arima
changing mode of //anaconda/envs/pmdissue23/bin/cython to 755
changing mode of //anaconda/envs/pmdissue23/bin/cygdb to 755
changing mode of //anaconda/envs/pmdissue23/bin/cythonize to 755
Successfully installed Cython-0.28.1 pyramid-arima-0.6.2
Cleaning up...
But again the package is not installed correctly and pycharm asks me to download the package. This leads me to the following questions.
I am using Pycharm on windows 10 and having issues how pycharm is configured to use python. I installed python and Anaconda on my system prior to installation of Pycharm. I selected the interpreter as Anaconda when I created the first program.
Below are my questions:
Why is pycharm creating a new virtual environment for python interpreter instead of using the original installation. ( This causes me to import all the packages for each new project I create)
Should I use Anaconda or Python interpreter. I am not sure which one is the right one. Or should I have both.
I am having problems installing packages (pycharm gives me an error that my pip is not updated). However from my command line I updated the pip to the latest version. How do I connect pycharm to the latest pip.
Last question, How can I import all the data science packages to my python installation and point pycharm to read those packages instead of writing explicit import statements.
Any help would be greatly appreciated. Thanks
I reinstalled python on my machine. Updated the pip and other packages.

Related

chocolatey says it has successfully force reinstalled python 3.11 - but I can't find it

Windows 11.
I am not great at virtual environments, and I have bumped around between a half dozen different "solutions." I thought I had it solved with chocolatey, but I am trying to install python3.11, and not having success. Basically, choco says it is installed, but I can't find it anywhere.
C:\Windows\System32>choco install --force python --version=3.11
Chocolatey v1.2.0
Installing the following packages:
python
By installing, you accept licenses for the packages.
python v3.11.0 already installed. Forcing reinstall of version '3.11.0'.
Please use upgrade if you meant to upgrade to a new version.
Progress: Downloading python 3.11.0... 100%
python v3.11.0 (forced) [Approved]
python package files install completed. Performing other installation steps.
The install of python was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\python'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
C:\Windows\System32>
This gives the impression that python would be in C:\ProgramData\chocolatey\lib\python, but the only files in that directory are python.nupkgandpython.nuspec`
Where do I go to find my shiny new python?
From PowerShell, run get-command python.exe
And you will get something like this:
CommandType Name Version Source
----------- ---- ------- ------
Application python.exe 0.0.0.0 C:\Users\Paul\AppData\Local\Microsoft\WindowsApps\python.exe
The Source column is where it is running python.exe from and where python is installed.
The python package on the Chocolatey Community Repository is a metapackage. So it does not install python, instead, it has a dependency on python2 or python3 (depending on the version of python), that dependent package is what actually installs Python. So if you install python v3.11, that will have a dependency on python3 v3.11, and the python3 package will download and run the Python installer.
Instead of force installing python, try for installing python3 to rerun the Python installer.
As for the install location, packages install to $env:ChocolateyInstall\lib\. So the .nupkg, .nuspec, chocolateyInstall.ps1, etc will all be there. But the python3 package runs the Python installer, and the Python 3.11.x installer will by default install to C:\python311 when run by the chocolateyInstall.ps1 in the python3 package.

How to pip install GDAL on Python 3.6 venv

gdal is correctly installed on my global system's python 3.5 packages.
But now I'm trying to pip install gdal on my python 3.6 virtual environment, but I receive multiple errors.
After activating the virtual environment, I've tried the following:
pip install pygdal or pip3 install pygdal
Error received: ERROR: Failed building wheel for pygdal
Tried following this guide, but the commands stated there are outdated
I've also tried this solution and this which failed
Installed older gdal versions but also didn't work.
Tried pip3 install GDAL==$(gdal-config --version) and I get the same error
I use
Ubuntu 16.04 and pip 21.0.1. Venv was created using virtualenv --python=/usr/bin/python3.6 my_venv
I've finally fixed the problem, and these are the steps I followed:
I uninstalled wheel from my venv
Then I pip installed gdal on the venv to check what error would appear
A wall of error text appeared, in which somewhere I noticed the 'x86_64-linux-gnu-gcc' failed with exit status 1
I typed sudo apt-get install python3.6-dev to install missing packages, as the solution suggests here
Then I ran pip install GDAL=<version that appears on ogrinfo --version> and it worked
EDIT: This answer pertains more to Windows than Ubuntu, but may have something useful.
Try downloading a wheel from here:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
Note the "cp##" in the middle - that should match your Python version. If you are running Python 3.6 then you should see "cp36" in the file name (a "cp37" in the name means the wheel will fail). Also pay attention to the amd64 and win32 to be sure you have the correct version to match your Python virtual environment.
I'm on Windows instead of Ubuntu, but this was my process:
Open command prompt with cmd
Copy the path to activate.bat in the virtual environment from Windows Explorer (hold shift down, right-click on file, choose
"copy as path")
Paste path into control panel and hit enter. You should see an indicator that you are in virtual environment.
Copy the path to the wheel you downloaded to the clipboard using the same shift key trick.
Type 'pip install ' then paste the wheel path from your clipboard (or type it all out manually)
As an aside, I ended up with gdal installed within the osgeo module. I tried several things before I got here, but I'm pretty sure that happened with my installation from the wheel. In Python, I now use
from osgeo import gdal
I hope something here helps you. I've run into this a few times and it never seems like I quite remember how I got it done the next time I run into it. If I remembered it right this time, I can refer back here.
FWIW - I am using PyCharm and installing gdal through the Project Interpreter doesn't work. Also, it may take some jostling in PyCharm for the skeletons to update after you install through command prompt.

Anaconda installation messed up the existing Python packages

For my project requirements I had installed Python packages like Jira and Bitbucket to connect to the servers using their API wrappers. After I installed Anaconda all the existing packages stopped working. Now Im getting No Module Found error for both Bitbucket and JIRA although the modules are already installed
For example :
pip3 install bitbucket-python
gives me that requirement is already satisfied. But when I run the code I get:
No module named "bitbucket" found
The same code was running fine 2 days ago before I installed anaconda.
Please help.
Now you have different versions of python and pip in your system. You have to make sure you are running correct version of the command. In my system with conda installed and activated pip3 refers to pip for system python. and pip for active conda python.
Try this: pip install bitbucket-python
you can use which command to see which binary is getting executed for example on my system.
dhananjay#ideapad:~$ which python
/home/dhananjay/.conda/bin/python
dhananjay#ideapad:~$ which pip
/home/dhananjay/.conda/bin/pip
dhananjay#ideapad:~$ which pip3
/usr/bin/pip3

Can't import tensorflow in PyCharm

I'm trying to import tensorflow in PyCharm, however I get an error that the module is not found.
I used pip install to install tensorflow.
Also when I look at the interpreter in PyCharm it says I have pip version 9.0.1 and the latest is 10.0.1. I have upgraded to 10.0.1 using the pip commands, and when I run pip --version it says I got 10.0.1.
I have tried both reinstalling pycharm and making new projects with no luck.
Go to Files -> Settings -> Project:projectname -> Project Interpreter
It's possible, that there is a different interpreter choosen for your project then the one you installed tensorflow in.
If you're running on linux you can check with "which pip" the path to your python distro in which you installed tensorflow.
This video explain it on a very simple way: https://www.youtube.com/watch?v=K9ypGzuP6xQ
Basically, TensorFlow is not by default installed on PyCharm virtual environment. You can do it by downloading in the Project Interpreter menu
try cleaning System Cache
On the main menu, choose File | Invalidate Caches/Restart.
The Invalidate Caches
Cleaning Cache

Using pip to install the same package in 2 different locations (Python)

For work-related reasons, I'm trying to install Python 2.7.8 directly onto my machine (Mac OSX 10.9).
I am current running Python 2.7.6 in Enthought Canopy, and I really don't want to touch the existing libraries there.
My problem is that I'd like to use pip to install packages for the new instantiation of Python, but currently pip is bundled up with Enthought Canopy, so it only installs packages in the site-packages path for Enthought Canopy.
I first tried the following:
pip install --install-option="--prefix=$PREFIX_PATH/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages" scikit-learn
But got the following error:
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in ./Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
Then, I tried to add the existing Enthought folder to the path for the newly installed Python 2.7.8, By entering the following line at the end of the .bash_profile:
PYTHONPATH=$PYTHONPATH:Users/***/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
This led to errors when trying to import some of the packages, probably for this reason:
Cannot import Scikit-Learn
I would really prefer just to install a new version of scikit-learn in a separate folder. Anyone have any suggestions?
You can use virtualenv to create a self-contained python environment that can be configured and used separately from your regular python installation.
Create the virtualenv (for oldish versions of virtualenv you'd want to include --no-site-packages right after virtualenv):
$ virtualenv limitedenv
Using base prefix '/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3'
New python executable in limitedenv/bin/python3
Also creating executable in limitedenv/bin/python
Installing setuptools, pip...done.
Move into the virtualenv and activate it:
$ cd limitedenv/
$ source bin/activate
(limitedenv)$
Install the packages you're after with pip as you'd do globally:
(limitedenv)$ pip install scikit-learn
Downloading/unpacking scikit-learn
Downloading scikit-learn-0.15.0.tar.gz (7.0MB): ...
scikit-learn will now be installed just inside limitedenv, and as long as you have that environment active, invoking python or pip will be like this is your very own, secluded Python installation.
You can exit from the virtual environment by calling deactivate:
(limitedenv)$ deactivate
$
This allows you to have different versions of python by themselves, different versions of libraries pr. project and different configurations based on what your project requires. virtualenv is a very useful tool!

Categories