importing simpy in python - unnamed module error - python

I am trying to import simpy package in python, however I get the unnamed module error. I am on a Mac OSX and have anaconda installed. I installed it using pip install simpy command. These outputs could also be helpful:
$ which python
//anaconda/bin/python
$ pip list
simpy (3.0.10)
$ conda list
simpy 3.0.10 <pip>
(If relevant, I am using PyCharm as IDE)

The error could be caused by your project configuration in pycharm pointing to another python interpreter, maybe python3 or a virtualenv?
Check it by going through your project settings.
Make sure you are using the same interpreter in PyCharm as the one where you installed your module.

Related

Mac M1 Spyder : ModuleNotFoundError: No module named 'lxml'

I am using Mac M1 now, when I am trying to import lxml in my python code, it shows below:
I've tried
my Python version is : Python 3.9.12
my lxml version is: 4.9.1
The main reason Spyder can't find 'lxml' is I used standalone Spyder, in order to fix this, I have to use a separate environment.
1 - Follow below article to create a new virtual environment
https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment
2 - Follow below article to install necessary packages in the new environment, which link to Spyder IDE later, all issues will be fixed.
https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#installing-packages-into-the-same-environment-as-spyder
Your development environment may be using a different Python installation. Run python -c "import lxml" in the same shell where you ran pip install .... If that works, then configure your development environment (there is an FAQ link on your screenshot).
It may also happen that pip and python belong to different Python installations. To fix it, use python -m pip install ... instead of pip install ....
For example, if you run python -m pip install lxml, that should install lxml, then running python -c "import lxml; print('OK')" should display OK.

distutils and pygame for python 3.7 on a machine running python 3.8

I'm quite new to Ubuntu. On my machine, running Ubuntu 20.04 with Python 3.8, I'm trying to run a program which does not support Python 3.8, but it requires Python 3.7 (FYI, it is Carla Simulator).
I need pygame, but when installing it through pip (python3.7 -m pip install pygame) it raises an error:
ModuleNotFoundError: No module named 'distutils.util'
Now, I have distutils correctly installed and updated at version 3.8.2-1ubuntu1.
Is there any way for me to install a distutils version compatible with Python 3.7 without affecting Python 3.8 and related modules? Or do you have hany suggestion to get pygame for Python 3.7 and running Carla somehow? Could a virtual environment help?
My question is really similar to this one How to install python-distutils but I don't actually require distutils, I just need the program to work...
Thank you
----- EDIT -----
I tried creating a virtual environment using venv, but I got an error due tue unavailability of ensurepip. Googling it, I found it might be related to the fact that my Python 3.7 version might have been installed through Anaconda (I actually can't remember). Running apt-cache rdepends python3.7 I get:
python3.7
Reverse Depends:
python3.7-minimal
Is it safe to completely uninstall current Python3.7 and reinstall it to hopefully get ensurepip? Any suggested code to safely do it?
The easiest solution for you would be to run your program in a virtual environment where you would specify the default python version to be 3.7 I think (see Use different Python version with virtualenv for an example). You can then install all your dependencies inside this environment and not have to deal with any conflicts between the two versions on Python.
Using pyenv you could specify the python version you want to use.
for example:
create a new folder and hit:
pyenv local 3.7.2
then create your virtual env by using pipenv:
pipenv install
then start your journey to building your game.
hope it help.

unable to install pymorph

I'm trying to install 'pymorph' on mac os x with 'PIP':
sudo pip install pymorph
I'm getting the following error:
NameError: name 'execfile' is not defined
Command "python setup.py egg_info" failed with error code 1 in
/private/tmp/pip-build-9hjd5tfm/pymorph/
I have read that using a python version different from 2.7 could lead to this kind of problem. Yet, I'm using the 2.7 version:
python --version
Python 2.7.13
Any ideas to solve this issue ?
Thank you in advance
It's possible to have a pip command on your PATH that comes from a different Python installation than the python command. (Each entry script to a Python-based tool is bound to the Python installation that was used to install the package that provided it. This means that the pip command does not search PATH for a python installation.) If this pip comes up later on PATH than python, it would lead to behaviour that you describe.
This can happen, say, if you first install a Python 2.7 without pip, and then a Python 3.x with pip, if the installers prepend to PATH.
You can verify which version of Python pip is using and where it's installed by running pip -V.
The robust solution to this should be using a virtual environment that lets you tie the base python installation and libraries specific to your application alone with your project, as well as avoid cluttering your global site-packages, and prevent inadvertent compatibility issues from different versions of the same package being needed by different projects.
It seems that the current (as of late 2017) recommended virtual environment solution is Pipenv. A decent-looking introduction to virtual environments using Pipenv, by the author of Pipenv, can be found here.

Python 2.7 can't find module Tkinter with the capital T

I am trying to run some plotting libraries that use Tkinter. I am using Python 2.7, and am getting the exact error (capitalization important :))
ImportError: No module named Tkinter
Seems like a lot of people are running into a similar issue that is solved by making sure to use the capitalized Tkinter versus all lowercase tkinter. I do not believe this is my problem since it is in fact capitalized.
When I run:
python --version
I get:
Python 2.7.5
Is there a place I can check to make sure Tkinter is properly installed? Has anyone else seen this particular issue with Python 2.7?
First, run pip freeze from the directory you want to use it. If you use a virtual environment, make sure that's active. This will show you all packages currently installed
The more exact option is to check the site-packages where they get installed (I use ipython):
How do I find the location of my Python site-packages directory?
$ ipython
In [1]: import site
In [2]: site.getsitepackages()
Out[2]:
['/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages',
'/Library/Python/3.6/site-packages']
then go there:
cchilders:/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
$ ls
IPython jupyter_client python_dateutil-2.6.0.dist-info
Jinja2-2.9.6.dist-info jupyter_client-5.0.1.dist-info pytz
MarkupSafe-1.0.dist-info jupyter_console pytz-2017.2.dist-info
Pygments-2.2.0.dist-info jupyter_console-5.1.0.dist-info pyzmq-16.0.2.dist-info
__pycache__ jupyter_core qtconsole
appnope jupyter_core-4.3.0.dist-info qtconsole-4.3.0.dist-info
...etc...
The same things you saw on pip freeze should show up here.
Make sure you have the package for the right version of python. If using python 3, you have to say:
pip3 freeze
But apparently the safest way to install is using apt if you have linux:
sudo apt-get install python-tk
Install tkinter for Python

Installing Python Libraries When Multiple Versions of Python Exist

When I run python -V from terminal, I see that Python 2.7.10 is installed. I want to keep this as the "global" version as OSX utilizes it.
When I run Idle, I see that Python 3.6.0 is running. How do I install libraries to this version of Python?
For example, if I run pip install bs4, the library is installed here beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.5.3-py2.7.egg - which is obviously Python 2.7.
So when I run my script from Idle, I get the following error:
ModuleNotFoundError: No module named 'bs4'
You want to use virtualenv. It sounds like you have two versions of Python installed and you need to focus on one while being able to manage the packages in each. Virtualenv will do this for you.
First install virtualenv (https://virtualenv.pypa.io/en/stable/),
Second run it specifying the version of python you want as so: `virtualenv -p /usr/bin/python2.6
Third you can use pip to install packages directly into this environment. This increases the amount of disk space you need, but will allow you greater control over your code.
When you have two versions of python, you will need to specify which version of python you would like to run. You can do this with the activate command. For example:
activate python3
Once you have activated the python 3 environment, you can then run pip:
pip3 install bs4
which will install the beautiful soup library in your python 3 environment.
Another answer was found here: https://stackoverflow.com/a/4910393/1580659
pipVERSIONNUMBER install will install the library to the correct version of Python.
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage

Categories

Resources