Socketio installing problems - python-3.x

I'm facing a problem with socketio. I imported it into my programme by command:
import socketio
Wen I typped pip freeze I got:
python-socketio==4.5.1
Then I ran programme by typing into console:
myfile.py --mode "mode"
But it says:
ModuleNotFoundError: No module named 'socketio'
Any ideas how to fix it?

It happens when you have multiple version of pip install on your system.
you can deal with this problem by creating a virtual environment and again loading the socket-io library.
Install pipenv.
pip install pipenv
Then change directory to the folder containing your Python project and initiate Pipenv,
cd your_project
pipenv install
This will build two new files in your project directory, Pipfile and Pipfile.lock, and a new virtual environment for your project, if it doesn't already exist. If you add the —two or —three flags to the last command above, your project will be initialized with the use of Python 2 or 3. Otherwise, Python's default version will be included.
To install a Python package for your project use the install keyword. For example,
pipenv install beautifulsoup4
and for uninstalling
pipenv uninstall beautifulsoup4

Related

Python Quickstart ModuleNotFoundError: No module named 'google_auth_oauthlib'

I set up a venv for my project and ran pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib to get the Google packages (after activating the venv).
When I attempt to run the Python Quickstart code (which I copy/pasted into my VScode project) I get the error: ModuleNotFoundError: No module named 'google_auth_oauthlib'. I ran pip list and verified that version 0.4.2 is installed.
My setup:
MacOS 10.15.07
VScode 1.53.2
venv Python 3.7.7
To be sure, activate the virtual environment in the shell you will use to run the quickstart and run pip freeze. Additionally make sure your the python you are using is the one in the venv. You can do which python
Maybe try using pip3 install instead? This is what fixed it for me.

Install the latest version of my package from working directory into my local environment using Python's poetry

It's extremely useful for the development workflow to be able to build and install the latest version of a package into a local environment. You can then interactively validate and debug by importing this latest version into a Python shell or a Jupyter notebook. The problem is I've recently adopted Poetry and cannot figure how to do this now. So...
How do I install the latest version of my package from the current working directory into my local environment using Poetry?
Moving on from setuptools
Back in the day, I used to always use setuptools and it worked great. I'd put a setup.py file in the root of my repository, create a virtual environment (let's say using conda) for the project, and do...
pip install -e .
From here, I could fire up a python shell, or even configure a jupyter kernel to use this virtual environment, and I'd always have the latest version of my package to interact with.
Now setuptools has its limitations, and we've since moved on to Poetry to more tightly control dependencies and handle more sophisticated build needs and such.
The problem with poetry
If you look up what's the pip install -e . equivalent in poetry you will find this issue. Looks like the creator of poetry thinks installing directly from source like this is a hack and has no interest in supporting it. (BTW: I've tried poetry build and then pulling out the setup.py file like he suggested and it does not work)
Linking directly to source is not necessary, I'm willing to run an install command to get the latest version of the package. And when I do this with poetry, it appears to work.
cd root/of/my/project
poetry install
Installing dependencies from lock file
No dependencies to install or update
Installing the current project: my-project (0.4.8) <-- this is the latest version according to the source code in the working directory
The problem is that if I open a Python shell and try and import my package for instance, it is linked to the last version of my package that installed from a remote artifact repository (via pip install my-package) – not what's in my working directory.
python
...
>>> import my_package
>>> my_package.__version__
'0.4.7`
Now, even though I'm using poetry I'm using a conda environment to specify the Python version for my project and then installing, and using, poetry from inside that.
source activate my-package
(my-package) ... $ poetry update
I also know that poetry (not very transparently) can create and manage its own virtual environment on your behalf. I thought maybe the reason this is not working is because I need to be inside this environment (whereas I was only inside my conda environment, while poetry is installing the 0.4.8 version of my package within the virtual environment it manages).
I tried both shell and run to test this out. I get the same result.
poetry shell
Virtual environment already activated: /Users/U6020643/.conda/envs/my-package
Python 3.8.5
...
>>> import my_package
>>> my_package.__version__
'0.4.7`
What gives?
The way I fixed this: I stopped using conda to manage the Python version for projects that involve poetry and instead use pyenv.
Below is how I made that work. This was very helpful!
1. Removing conda as default environment manager.
This involved removing conda base activate from ~/.bash_profile.
Now open a new shell and verify that there's no conda environment prefix, e.g. (base) ... $.
2. Installing pyenv using Homebrew
Had been awhile, and an OS upgrade or two, since I interacted with Homebrew. Needed to do some housekeeping.
brew cleanup # This made it so that brew update didn't take forever
brew update
brew upgrade
brew cleanup
Then...
brew install pyenv
3. Install Python version(s)
Let's say you need/want Python 3.
pyenv install 3.8.5
4. Set the local Python version for your project
cd your/project/root/
pyenv local 3.8.5
5. Install poetry
See here.
6. Use it
Now install and use shell. Check the version -> hey it works!
cd your/project/root
poetry install
poetry shell
my_package --version # Package has a CLI.

Pip install installs libraries into different locations

I have just started using python and I have set up python3 to be installed in C:\Python37 dir. I have added python3 path to environment variables. When I run python3 -m pip install [package_name] it installs it in C:\Python37\Lib\site-packages. But when I try to install pylint with python3 -m pip install pylint it prints:
Requirement already satisfied: pylint in c:\users\radio\appdata\roaming\python\python37\site-packages (2.3.1)
It's installing it in above mentioned completely different location, and then VS Code complains how pylint is not installed. Why doesn't pip install it in C:\Python37\Lib\site-packages where it installs all the other packages?
It seems you might have multiple python installations on the computer or you are not running CMD with administrator priviledges when using pip.
I would refer you to this thread: windows pip installing libraries in wrong directory which seems to deal with a problem similar to the one you are having.
I would also try checking the environment variables to see the path set for Python if that doesn't work.

Can I create a virtualenv after making the mistake of installing all project packages globally?

So I am a python newb like first project ever newb. I jumped right in disregarding virtualenv and installed everything globally. Now I need to be able to share my project with other team members.
Can I create a virtualenv after making the mistake of installing all project packages globally?
I am using python 3. I've read these links:
pip installing in global site-packages instead of virtualenv
How to import a globally installed package to virtualenv folder
But I don't think thats what Im looking for. I want to go the requirements.txt route I think.
Any guidance or suggestions?
Yes, you can create a virtual env.
You can create a requirements.txt file for the packages you installed globally.
pip3 freeze > requirements.txt
and then you can use this requirements file for installing all the packages in the virtual env which will be isolated from your global environment.
First you need to install virtualenv:
pip3 install virtualenv
Create a new virtual env using the following command:
virtualenv -p python3 envname
You can activate the virtualenv by:
source /path/to/new/virtual/environment/bin/activate
To deactivate the environment and return to your local environment just run:
deactivate
Install the requirements from the file.
cat requirements.txt | xargs -n 1 pip3 install
This should install all your packages in the virtual environment.
To check which python you are using use which python command and to check installed packages use pip3 list
I hope this will clear your doubt.

pip install chromedriver only installed python bindings

When I use the command "pip install chromedriver" and checked the directory. It installed a directory named "chromedriver" and only have init.py and pycache inside, rather than a executable file.
Is this because some errors of my environment and how can I fix it?
Isn't the name of the package you want to install rather chromedriver_installer. So try to install chromedriver_installer with pip install chromedriver_installer and see if this works.

Resources