Module or Incorrect Python Version Problem? - python

I'm installing a bunch of python modules on my system that are specific to this code I am going to be working with. Specifically, I used pip install pyda to get the pyda module. To make sure I had gotten all the modules, I went through and ran some of the code snippets, and came across the following error:
ModuleNotFoundError: No module named 'pyda.utilities'
I tried using pip install pyda.utilities, but that honestly doesn't make sense, it should have just come with the pyda module. According to this website https://pypi.org/project/pyda/ it seems like it should come with the package. I tried determining if I just installed it in the wrong python version, but I'm having a difficult time forcing it to use the specific python version that I installed the module in (specifically, I tried to create an alias for /usr/bin/python3.7 or something like this as I have seen on other websites, but it just fusses at me that this is simply a directory, incredibly unhelpful because I can't find the corresponding executable, so I'm a bit confused here).
This is a very long question likely with a very simple answer, any thoughts or help on what the issue might be would be appreciated.
Edit: I have determined that it's a package problem, not a python problem. The command 'pip install pyda' is not actually installing everything, oddly enough, which is why it cannot find the pyda.utilities module. Unfortunately, I think this means I will have to install the package manually. I will keep this question posted because of the useful answer on virtual environments, so thanks everyone.

The answer is indeed straightforward. As #Chris indicated in the comments, start using virtual environments.
It's not as complicated as it sounds and there's plenty of tutorials on getting started with virtualenv for Python, like https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/
The basic steps:
check you're using the version of Python you want in your virtual environment
if you don't, change directories to where it lives
ensure you have pip and it works
check if you have virtualenv and if you don't pip install virtualenv
create a virtual environment virtualenv /your/env/folder/here
activate the virtual environment with /your/env/folder/here/Scripts/activate
After that, just install the packages you need with pip and they will end up in your virtual environment, with no interference from other Python versions or packages.

Check your python version, if it does not work restart your computer and try run setup.py install on the python command line

Related

Do executables like pip.exe require python to work?

I am relatively new to Python so please pardon my ignorance. I want to know answer to following questions
How does pip know the location to install packages that it installs? After a built of trial and error
I suspect that it maybe hardcoded at time of installation.
Are executables like pip.exe what they call frozen binaries? In essence, does it mean that pip.exe will run without python. Again after a bit of trial and error i suspect that it requires a python installation to execute.
P.S: I know about sys.prefix,sys.executable and sys.exec_prefix. If there is anything else on which the questions i asked on depends, pls link me to same.
PIP is a package manager for Python packages, or modules if you like.
pip when used with virtualenv will generally install packages in the path /lib//site-packages.
For example, I created a test virtualenv named test, and the django folder is in test/lib/python3.7/site-packages/django.
At the time of installation, you must have set up environment variables, and that is how pip recognizes directories.
pip.exe which is placed under path\Scripts needs a python installation and can't run without one. It is hardwired against a specific python interpreter, and can't install packages for another one. If you have 7 different python versions installed on your system, you will also have 7 different versions of pip.
Since it is bound so tightly, pip was at some point even included with the python standard library (see pep-0453 for details).
This also answers the other part of your question of how pip figures out the right location - there is only one location it can install to, the side-packages of the python interpreter it is bundled against.

How to add pip to path

I used cmd and did pip install requests. However when I go to write my code it gives me an error that I don't have a module named requests but when I run pip list in cmd it says it in the list.
The best way to manage your Python modules and projects is using Anaconda. Install Anaconda for Windows and you can create Virtual environments for individual projects that is a good practice. Good Luck!
You probably dont have the library in the environment you are using. If you are using a IDE like pycharm ensure under interpreter you have the library there.
I dont think the issue is not having pip in your path.

Messed up Python packages installement? (OS X)

I think i somehow messed up installing packages for python and the whole environment. Whenever i want to install something i run into problems like:
directory is not owned by the current user and the cache has been disabled
Also PyCharm thinks i still need to install referenced packages (no modules. Which is wrong since i can use them. When i click on 'install referenced packages' i get the mentioned warning from above plus:
OSError: [Errno 1] Operation not permitted
Hopefully one of you can help! :(
Best regards
Matthias
Edit: At some point i also installed a venv for python. Maybe this relates to my problem. I'm rly sorry i am new to it and have no idea what i'm doing.
You have an issue with your permissions, if you run
which python
you will see where your current version of python is installed. If you're on osx, I seriously recommend downloading brew here: https://brew.sh/. Just paste that command into your terminal, then you should install python by running:
brew install python
This will give you some later instructions, but the brew bundled version of python is alot more robust than the one that gets bundled with your system. Another note is that if you're using virtual environments, consider using virtualenvwrapper here. This should make things run alot more smoothly for you :)
Hope that helps.

Namespace package with both tarball and egg in Python

I've followed this tutorial to make a package with namespace. Then I use pip install xxx.tar.gz to install and everything works like expect.
The problem is that my environment has already a lots of packages with the same namespace and installed with easy_install and eggs, and python can not find the old packages anymore. I understand that if I create tar.gz instead of eggs for all the olds pacakges, it would work fine but this is a lots of time to spend.
How can I make the new and old packages work together with two different installation methods ?
Thanks
I just ran into the same problem (I think). It appears that this is a well known problem. The solution given to me was to just use pip for everything. I was specifically using python setup.py install alongside pip install w/e and it wasn't working, I'm guessing yours is roughly the same problem.

Cleaning Python modules an have fresh start Mac OS X

I am not a total newbie but I am trying to install modules for quite a long time and at this point i would like to have a fresh start and install python and all the modules I need so i really understand them. My problem is that some of them import, but most of them install either to the wrong site-packages or dont import maybe because i messed up my system/python. Also I tried the PYTHONPATH and PATH to set this up right, but it never worked.
So my questions are:
Is there a way to ensure I can clean everything up and start from zero ?
Ideally this would be without having to set up Mac OSX new.
Is there a way to install all the modules in the correct place (whatever the directory is I dont care, it should just work)?
Is there a good step-by-step description on how installing modules works. And I dont mean just the info to use easy_install, pip install etc, but a way to fully understand what I need to consider, where I need to put them, why these modules are recognized in certain directories, how the system finds them and most important what are the most common pitfalls and how to avoid them.
I also tried Macports and various other similiar ways to install but even if some of them worked and while I am sure that these are really great tools, most I had to hack to work.
So if someone can recommend a good and stable way to install a lot of modules at once, this would be incredibly useful.
Thanks a lot !!!!
And sorry for the long questions.
Buildout and virtualenv should be what you are looking for.
Buildout helps you configure a python installation and virtualenv allows you to isolate multiple different configurations from each other.
Here's a nice blog post explaining how to use them together.
Also, see this other question: Buildout and Virtualenv
You can safely install an up-to-date Python 2 and/or Python 3 on OS X using the python.org installers here. They will coexist with any other Pythons you have installed or that were shipped by Apple with OS X. To install packages, for each Python instance first install Distribute which will install a version-specific easy_install command, i.e. easy_install-2.7 or easy_install-3.2. Many people prefer to use pip to manage packages; you can use easy_install to install a version-specific copy of it. If you want something fancier, you could also install virtualenv but, with the isolation provided by Python framework builds on OS X, that isn't as necessary as on most other platforms.
Is there a way to install all the modules in the correct place?
Download and untar/gunzip/etc the module source (Most of the modules ares available in gzip form at http://pypi.python.org/pypi), then run configure with --prefix set to the same thing for every install:
[ 11:06 jon#hozbox.com ~ ]$ ./configure --prefix=/usr/local
/usr/local is usually the default, but it doesn't hurt to specify it and will ensure that every module you install will be placed in /usr/local/lib/python/...
Is there a good step-by-step description on how installing modules works?
The Python website has a great page called: Installing Python Modules
http://pypi.python.org/pypi
http://docs.python.org/install/index.html

Categories

Resources